Longest Word
How This Converter Works
Finds the first longest non-whitespace run. Punctuation stays attached to its run, ties keep the earliest run, and length comparison uses UTF-16 code units.
Formula or rule
Find all /\S+/ matches and select the first match with the greatest JavaScript .length.
Example
- Input
- red watermelon pear
- Calculation
- The non-whitespace runs have lengths 3, 10, and 4; watermelon is longest.
- Result
- Longest Word - watermelon