I am working with python regular expression basics .I have a string
startabcsdendsffstartsdfsdfendsstartdfsfend.
How do i get the strings in between consecutive start and end without matching the entire string?
use the start.*?end in the re. The question mark means "as few as possible".
>>> s = "startabcsdendsffstartsdfsdfendsstartdfsfend."
>>> import re
>>> p = re.compile('start(.*?)end')
>>> p.findall(s)
['abcsd', 'sdfsdf', 'dfsf']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With