-1

I have this string:

"You to You know to You have to know Regex more You have to know everything of Regex"

I want to get result of pattern: (You) (to) (Regex). That is:

"You to You know to (You) have (to) know (Regex) more (You) have (to) know everything of (Regex)"

But my regex gets this:

"(You) (to) You know to You have to know (Regex) more (You) have (to) know everything of (Regex)"

REGEX: (You).+?(?=to)(to).+?(?=Regex)(Regex)

I know my Regex work right as described, but I don't know how to skip First 'You'.

Thanks.

Luis
  • 23
  • 6

1 Answers1

1

you are looking for:

(?i)(you)(?:(?!you).)*(to)(?:(?!to).)*(regex)

The explanation and Demonstration can be found HERE.

Onyambu
  • 31,432
  • 2
  • 14
  • 36
  • Thanks, but instead of "Skpping first occurrence", I want just neighbor-linked pattern. I updated string again. "You to You know to You have to know Regex more You have to know everything of Regex" – Luis Nov 19 '18 at 08:49
  • @Luis I am not skipping the first one. Check again. Try using the regex I gave you on your new example. It still captures what you want. It is the logic. I am not skipping anything. The logic is that you should be followed with to and then Regex. That is the logic I used for the regex – Onyambu Nov 19 '18 at 08:58
  • Yes, your answer is best! – Luis Nov 19 '18 at 09:18