-2

I`m searching for regex which will count how many times caret will stop between 2 words. Caret must be carrying just forward with ctrl + "right arrow" btn.

for example: word word - 1 caret stop empty space - 1 caret transition to next word

word, word - 2 caret will stop upon coma next ctrl+arrowRight will move it to the start of next word

word...word - 2 caret stops

word , word - 2 caret stops etc...

is there exist some magic regex to solve such issue?

echo_54
  • 1
  • 1

1 Answers1

0

You can't detect caret stops, they are not characters. It is essentially and action that looks for the next word and places the caret there. What you can do is match word boundaries. They are invisible characters that can be detected before the start or at the end of a word.

'The quick brown fox jumped over the lazy dog.'.match(/(?:\s|^)\b/g)

Here is an example: https://regex101.com/r/s3LS2K/2

Utilizing a regular expression count function, like this one, you can get a count of matches.

Jim
  • 3,210
  • 2
  • 17
  • 23