Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
Python 使用正则表达式检测twitter句柄_Python_Regex_Python 3.x - Fatal编程技术网

Python 使用正则表达式检测twitter句柄

Python 使用正则表达式检测twitter句柄,python,regex,python-3.x,Python,Regex,Python 3.x,我正在尝试使用正则表达式来检测twitter上的提及。示例消息是,“@This_匹配hello@doesnt@match“比赛进行得怎么样?” 我使用的是: m_list = re.findall(r'(?<!\w)(@\w{1,15})(?=\s)' ,a) m_list=re.findall(r'(?)? \b单词边界您可以将最后一个正向前瞻替换为反向前瞻 m_list = re.findall(r'(?<!\w)(@\w{1,15})(?!\S)' ,a) m_list=r

我正在尝试使用正则表达式来检测twitter上的提及。示例消息是,“@This_匹配hello@doesnt@match“比赛进行得怎么样?”

我使用的是:

m_list = re.findall(r'(?<!\w)(@\w{1,15})(?=\s)' ,a)
m_list=re.findall(r'(?)?

\b单词边界

您可以将最后一个正向前瞻替换为反向前瞻

m_list = re.findall(r'(?<!\w)(@\w{1,15})(?!\S)' ,a)

m_list=re.findall(r')(?您的第一部分答案似乎很有效!谢谢。对不起,我马上就来,我还有一个问题。
(?在被赋予@foo时失败。我不想让@foo工作。因为它只检测到整个@foo中的最后一部分@foo。当@Armageddon80
(?或者干脆
)后面有另一个“@”时,我怎么会不匹配呢?(注意,Twitter API已经提取了提到的内容。)。
m_list = re.findall(r'(?<!\w)(@\w{1,15})\b' ,a)

                                        ^^
m_list = re.findall(r'(?<!\w)(@\w{1,15})(?!\S)' ,a)