0

I have this regex(example) below:

/([A-Z][a-z]+\s[A-Z][a-z]+)/gm

And the following text as a example:

"well, this is a Random text Just To Explain my Question, What can IDo? Please Help Me"

I'd expected that the return from regex was:

1 - Just To
2 - To Explain
3 - Please Help
4 - Help Me

That's result that matches with my regex, but the real return from it is:

1 - Just To
2 - Please Help

How to build a new regex that returns my expected result? I've tried to do everything but i can't do that...

Ps.: I'm using javascript...

Thanks!

  • I think this has something to do with the way that regex process the string from start to end and is not actually possible with regex. – Ken Apr 21 '17 at 21:58
  • You have _consumed_ the word "To" when you matched "Just To" — since it is already part of a match it is not available to match again for "To Explain", therefore the next pair of capitalized words available to match is "Please Help". Again, the word "Help" has been consumed and the only part of the string available for more matching is " Me", which does not match the regex. – Stephen P Apr 21 '17 at 22:04

0 Answers0