Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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 Can';在我的正则表达式中找不到错误_Python_Regex - Fatal编程技术网

Python Can';在我的正则表达式中找不到错误

Python Can';在我的正则表达式中找不到错误,python,regex,Python,Regex,我正在尝试构建一个正则表达式,它能够从字符串中提取所有类似Stackoverflow的标记。我的正则表达式有问题,我找不到问题所在: s = 'call,me r c++ c# 132(list) 2345sdf;sdf_sfg? "adf-sdf aso.net?' re.findall(r"[^,\s;\"\(\)]*[a-zA-Z0-9_\+\-\.#]*[a-zA-Z0-9_\+\-#]", s.lower()) 我越来越 ['call', 'r', 'c++', 'c#',

我正在尝试构建一个正则表达式,它能够从字符串中提取所有类似Stackoverflow的标记。我的正则表达式有问题,我找不到问题所在:

s = 'call,me r c++ c# 132(list) 2345sdf;sdf_sfg? "adf-sdf aso.net?'
re.findall(r"[^,\s;\"\(\)]*[a-zA-Z0-9_\+\-\.#]*[a-zA-Z0-9_\+\-#]", s.lower())
我越来越

['call',
 'r',
 'c++',
 'c#',
 '132',
 'list',
 '2345sdf',
 'sdf_sfg',
 'adf-sdf',
 'aso.net']
正如你看到的,逗号后面的“我”不见了。我也愿意改进我的正则表达式

编辑:我要匹配的模式是有效的SO标记,即集合[a-zA-Z0-9+-.#]中的所有字符。我的其余表达是一个黑客,以排除在句子的末尾点和周围消除逗号的工作。< /P> <代码> > s=’调用,MeR+C+C++ 132(list)3545 SDF;sdf_sfg?“adf sdf aso.net?foo.bar.”
>>> s = 'call,me r c++ c# 132(list) 2345sdf;sdf_sfg? "adf-sdf aso.net? foo. bar.'
>>> re.findall(r'\b\w[\w#+.-]*(?<!\.)', s)
['call', 'me', 'r', 'c++', 'c#', '132', 'list', '2345sdf', 'sdf_sfg', 'adf-sdf', 'aso.net', 'foo', 'bar']

>>>关于findall(r'\b\w[\w#+.-]*(?您想要匹配的模式是什么?@thefourtheye,编辑了这个问题。我运行了您的示例,在我的python 2.7.3 Win 7上运行得很好。确保您的python是最新的。还有一些奇怪的事情,如嵌入的不可见字符或字符串编码问题。是的,您是对的。我在预处理的下一步中排除了“我”g、 如何排除字符串末尾的点?@elyase:您可以在模式的末尾添加一个负数lookback:
(?)?