我想使用正则表达式来匹配句子“,”之前的表达式
示例:我的名字是xxxx,我住在..,我是英国
结果应该是:我的名字是xxxx
谢谢!
请尝试
print(re.search(r'[(\w)(\s)]+',Exemple).group())
/([^,]+?),.*/在第一个everything that is not a comma中的第一个,之前捕获capture group。注意+?使得量词non-greedy
/([^,]+?),.*/
,
+?