I need a regex for finding a substring like
from xyzTableName with ( index =...
and
from xyzTableName ( index =...
If with keyword is not there then it should return a match and if with exists after FROM keyword and before ( then there should be no match. All the other words between from and ( must be ignored.
I have tried with below expression :
@"\bfrom.*[\s\t\n]+(?<!with)[\s\t\n]([\s\t\n]+index"
And some variants of same. I was able to work it out when there are only normal/single whitespaces. But when I tried with multiple white-spaces and line-breaks, It failed.
Try this pattern:
\bfrom\b(?!.+\bwith\b)[^(]+\(\s*indexThe above returns
false. Change the input to remove the word “with” and it will returntrue. By usingRegexOptions.Singlelinethe.metacharacter will match all characters, including newlines (\n).Pattern breakdown:
\bfrom\b: exactly matches the word “from” and uses word-boundary metacharacters(?!.+\bwith\b): negative look-ahead to check for “with” and the match will fail if it does[^(]+: negative character class to match any character that is not an opening parenthesis, at least once.\(\s*index: match an opening parenthesis (note that it has to be escaped), any whitespace, then the word “index”