I have a string of the format:
PATTERN or abcPATTERNdef or PATTERN or <<[TEST].[PATTERN]>>
I have created a regular expression (in JavaScript) as (^PATTERN)|([^\[]PATTERN) which is returning the first 3 occurrences while ignoring the last one, however I also seem to be getting the preceding character in the returned matches:
“PATTERN”, “cPATTERN” and ” PATTERN”
What I need are the matches without the preceding character.
I’m new to regular expressions and apologize if the question reflects that.
Any help would be greatly appreciated.
JavaScript doesn’t have good support for lookbehinds, but if your format is going to remain the same, you can try something like this:
It matches all occurrences of “PATTERN” that are not followed by a
].Let me know if this isn’t the case, and I will update my answer to include the check for the opening
[.