I met one problem when I use regex to match some string using Python.
Example string:
ln[1] --This is a string--
ln[2] Match the line below.
ln[3] --This is a string--
ln[4] Match this line start from here.
ln[5] -This is the end-
I want to extract abc in the string above.
code:
pattern = re.compile('%s(.*?)%s' % ('--This is a string--', '-This is the end-'))
re.findall(pattern, string)
How can I get the line 4 only, not get line 2 to line 4 ?
Thank you very much.
.*?-- what is it that you intend?abcwould work.ait encounters, and then keeps matching until thecis reached. If you don't want to allow more than onea, you need to tell the regex engine that.