[英]python regex not match last char
Im试图匹配用[/]内的/分隔的数字,但不包括最后一个字符,这是为什么? 但没有/
import re
regex = r"\[.+?\]"
Sample1= "text text text[One]"
Sample2= "text text text[One/Two]"
Sample3= "text text text[One/Two/Three]"
lines=[Sample1,Sample2,Sample3]
print([re.findall(r"\[(.+?)[^\/]\]", s) for s in lines])
现在的输出是:
[['On'], ['One/Tw'], ['One/Two/Thre']]
我想成为:
[['One'], ['One', 'Two'], ['One','Two','Three']]
正确的正则表达式是什么?
matches = [re.findall(r"\[(.+[^\/])\]", s) for s in lines]
print(matches)
这将起作用。 我已经纠正了正则表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.