Reputation: 31
I am trying to find certain lines in which "like" comes before the word "crusegdf". For example, given the following input:
def shared temp-table w-cruseg no-undo field cruise-id like crusegdf.segment-id
define {1} shared temp-table tt-history no-undo like crusegdf.
I only want to match the second line. But my regex finds both these lines. The regex that I use now is:
(?i)(define|def)(.*?)(temp-table)(.*?)(like)\s*(\bcrusegdf\b)\s*(\.)
Upvotes: 1
Views: 104
Reputation: 786291
You can use this negative lookahead regex for matching a like containing like
that doesn't contain define
before it:
^(?:(?!\bfield\b).)*like.*
(?:(?!\bfield\b).)*
will match 0 or more any characters that doesn't have field
at next position.
Upvotes: 0
Reputation: 425418
You can't use \b
to delimit your field name, because your input has field names that contain dots; the dot is not a "word" character.
Instead use a negative look ahead for a dot then more field name:
^(?i)(define|def).*?temp-table.*?like\s*\bcrusegdf\b(?!\.\w).*$
See live demo.
I also removed the unnecessary brackets (your question did not say you needed to capture input).
Upvotes: 1