I am trying to capture KEYWORD1 in .NET regex engine based on whether KeyWord2 is present in the string. So far the positive look-around solution I am using:
(?=.*KeyWord2)**KEYWORD1** (\m\i)
only captures KEYWORD1 if KeyWord2 is positioned anywhere behind KEYWORD1 in the string. How can I optimize this in regex so that it captures all instances of KEYWORD1 in the string despite the position of KeyWord2 being ahead, behind or both?
I'd really appreciate some insight.
Thank You
You can use the regex below for your requirement:
Explanation of the above Regular Expression:
You can find the above regex demo here.
NOTE - For the record, these engines support infinite lookbehind:
.NET (C#, VB.NET etc.)
Matthew Barnett's regex module for Python
JGSoft (EditPad etc.; not available in a programming language).
ECMASCRIPT(Javascript)
As far as I know, they are the only ones.