小编Sol*_*ris的帖子

Python正则表达式:查找不包含子字符串的子字符串

这是一个例子:

a = "one two three four five six one three four seven two"
m = re.search("one.*four", a)
Run Code Online (Sandbox Code Playgroud)

我想要的是找到从"一"到"四"的子串,其中不包含子串"两".答案应该是:m.group(0)="一三四",m.start()= 28,m.end()= 41

有没有办法用一条搜索线做到这一点?

python regex

4
推荐指数
2
解决办法
2640
查看次数

标签 统计

python ×1

regex ×1