I am using the below pattern to find all the data between two words, placed in multiple lines.
/START(.+?)END/
But this doesn't seems to work as expected. Can someone help me out with a exact pattern.
Thanks.
I am using the below pattern to find all the data between two words, placed in multiple lines.
/START(.+?)END/
But this doesn't seems to work as expected. Can someone help me out with a exact pattern.
Thanks.
Use the s
flag : with this flag, dot (.
) will match new line characters too.
/start(.+?)end/s
Do you mean you want to match things like
START
blah blah blah
more blah
and even more blah
END
? Since .
does not match newlines by default, your regex won't work. You need to supply the single-line (also known as "dot-all") /s
flag to make it match the newlines.
/START(.+?)END/s
assuming you can use Python for example.
>>> s="""
... START
... blah1 blah2
... more blah
... and even more blah
... END blah3 blah4 blah5 START blah 6
... text here here
... blah7 END ......
... START end END
... """
>>> for item in s.split("END"):
... if "START" in item:
... print item [ item.find("START")+len("START") : ]
...
blah1 blah2
more blah
and even more blah
blah 6
text here here
blah7
end
Split your string on "END", go through each splitted items, check for START,and do a substring. Use the split method of your preferred language.