I have this regex
(?<=TG00).*?(?=#)
which extracts all strings between TG00 and #. Demo: https://regex101.com/r/04oqua/1
Now, from above results I want to extract only the string which contains TG40 155963. How can I do it?
I have this regex
(?<=TG00).*?(?=#)
which extracts all strings between TG00 and #. Demo: https://regex101.com/r/04oqua/1
Now, from above results I want to extract only the string which contains TG40 155963. How can I do it?
Try this pattern:
TG00[^#]*TG40 155963[^#]*#
This pattern just says to find the string TG40 155963 in between TG00 and an ending #. For the sample data in your demo there were 3 matches.
You can use this regex with a lookahead and negated character class:
(?<=TG00)(?=[^#]*TG40 155963)[^#]+(?=#)
RegEx Explanation:
(?<=TG00): Assert that we have TG00 at previous position(?=[^#]*TG40 155963): Lookahead to assert we have string TG40 155963 after 0 or more non-# characters, ahead[^#]+: Match 1+ non-# characters