简体   繁体   中英

python regular expression repeating pattern matching entire string

I am working with python regular expression basics .I have a string

start abcsd end sff start sdfsdf end s start dfsf end .

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM