Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 查找字符串或字符的开头_Regex_Python 2.7_Regex Lookarounds - Fatal编程技术网

Regex 查找字符串或字符的开头

Regex 查找字符串或字符的开头,regex,python-2.7,regex-lookarounds,Regex,Python 2.7,Regex Lookarounds,命令 re.compile(ur"(?<=,| |^)(?:next to|near|beside|opp).+?(?=,|$)", re.IGNORECASE) re.compile(ur)(?re.compile(ur)(?:^ |)(?将re.findall与下面的正则表达式一起使用,因为如果存在任何捕获组,则re.findall必须返回捕获组中的内容 re.compile(ur"(?m)(?:[, ]|^)((?:next to|near|beside|opp).+?)(?:,|

命令

re.compile(ur"(?<=,| |^)(?:next to|near|beside|opp).+?(?=,|$)", re.IGNORECASE)

re.compile(ur)(?
re.compile(ur)(?:^ |)(?将
re.findall
与下面的正则表达式一起使用,因为如果存在任何捕获组,则
re.findall
必须返回捕获组中的内容

re.compile(ur"(?m)(?:[, ]|^)((?:next to|near|beside|opp).+?)(?:,|$)", re.IGNORECASE)

原因:
是1-宽度,
^
是0-宽度,Python无法处理不匹配。关于“原因”,请参见-”在字符串开头,或前面加空格或逗号“
”(?这对我来说很有效,但我不明白
(?m)
的作用。你能简单解释一下吗?
re.compile(ur"(?m)(?:[, ]|^)((?:next to|near|beside|opp).+?)(?:,|$)", re.IGNORECASE)