我找不到正则表达式的解决方案,该正则表达式仅在字符串的特定范围内寻找模式,但仅在字符串的特定范围内
我想找到$ $,但前提是它位于字符串的5-7位置,并且这两个之间的哪个字符都没有关系
例子
xxxx$x$xxxxx would match
xx$x$xxxxxxx would not
答案 0 :(得分:1)
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