[英]python regular expression repeating pattern matching entire string
I am working with python regular expression basics .I have a string 我正在使用python正则表达式基础。我有一个字符串
start abcsd end sff start sdfsdf end s start dfsf end .
启动 abcsd 结束 sff 启动 sdfsdf 结束 s 启动 dfsf 结束 。
How do i get the strings in between consecutive start and end without matching the entire string? 如何在连续的开始和结束之间获得字符串而不匹配整个字符串?
use the start.*?end
in the re. 在re中使用
start.*?end
。 The question mark means "as few as possible". 问号意味着“尽可能少”。
>>> s = "startabcsdendsffstartsdfsdfendsstartdfsfend."
>>> import re
>>> p = re.compile('start(.*?)end')
>>> p.findall(s)
['abcsd', 'sdfsdf', 'dfsf']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.