比方说,我有一个字符串变量
msg = "The issue is Keys on the keyboard are working intermittently . is it working? Was the Keyboard replaced earlier ?"
我想提取所有句子之间“”和“?”还“?”和“?”
预期输出:
["is it working", "Was the Keyboard replaced earlier "]
我想这种模式,但没有得到预期的输出
re.findall('(?<=\.).*(?=\?)',s)
更新后的字符串:
味精=“.The问题是键盘上的键是间歇性的工作,是它的工作?是键盘早些时候更换吗?”
您需要懒惰匹配。
所以,正则表达式应该是这样的。
(?<=\.|\?).*?\?
而你已经表现出我的正则表达式并没有捕捉问号开始的句子。
The issue is Keys on the keyboard are working intermittently . is it working? Was the Keyboard replaced earlier ?
正则表达式字符串:
(?<=\.|\?).*?\?
结果:
is it working?
Was the Keyboard replaced earlier ?
[!@#$%^&*()“:{} | <>]试试这个正则表达式来获得期望的模式。我认为你没有使用正确的正则表达式这个表达式会发现特殊。人物诠释字符串