I have a regular string as bellow:
xxSTART Here we have the first text in 1234 asdf xxENDxxSTART Here we have the second text 999 fffd xxENDxxSTART Here we have the third text 1234 9985Df xxENDxxSTART Here we have the fourth text 1234 asdf Dert xxEND
I'm using the follow REGEX: ^(?:(.*?)\K(xxSTART)){3}(.*?xxEND)
to get ONLY third match xxSTART Here we have the third text 1234 9985Df xxEND
. This work well in http://www.regexr.com/v1/, but i read a article saying \K
option is not a option in C# (Support of \K in regex), and the article Translate Perl regular expressions to .NET say to use look-behind ((?<=…))
instead. But i cant use look-behind ((?<=…))
in my RegEX, anybody can help me? please!!
Anyone have a ideia how to use ((?<=…))
in my RegEX ^(?:(.*?)\K(xxSTART)){3}(.*?xxEND)
to replace \K
option?
Thank Regards,
You don't really need a lookbehind here, you can match the xxSTART
and still get the 3rd part that you want to get:
^(?:xxSTART.*?){3}\s*(.*?)xxEND
But if you really want to use a lookbehind (in case you don't want any capture groups, well, in this case, you can consider using a lookahead for the xxEND
), you would use something like this:
(?<=^(?:xxSTART.*?){3}\s*).*?(?=xxEND)