regex to extract consecutive single-line comments when a specific string
is contained within
Consider an SQL file as follows that contains a number of single-line
comments:
-- I'm a little teapot
<<< not a comment >>>
-- some random junk
-- random Mary had a
-- little lamb random
-- more random junk
<<< not a comment >>>
Using regex, I was looking to match the string Mary.*?lamb and extract all
consecutive (above and below) single line comments.
The expected output would be:
-- some random junk
-- random Mary had a
-- little lamb random
-- more random junk
I was trying something along these lines but had no luck.
(--[\S\t\x20]*\n)*?(--[\S\t\x20]*?Mary[\S\t\x20]*?\n)(--[\S\t\x20]*\n)*
No comments:
Post a Comment