我无法找到一个正则表达式的解决方案,它只在字符串的特定范围内查找模式我想找到$ $,但是只有当它在字符串的5-7位置,并且这两个字符之间的字符无关紧要示例
xxxx$x$xxxxx would match xx$x$xxxxxxx would not
iswrvxsc1#
import re should = "xxxx$x$xxxxx would match" shouldnt = "xx$x$xxxxxxx would not" pattern = r'^.{4}\$.\$.+' re.match(pattern, should) re.match(pattern, shouldnt)
给予
match None
https://regex101.com/r/RLHrZb/1
1条答案
按热度按时间iswrvxsc1#
给予
https://regex101.com/r/RLHrZb/1