\B assert position where \b does not match
' matches the character ' literally (case sensitive)
Non-capturing group (?:[^']*(?:'\b)?)+
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character not present in the list below [^']*
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
' matches the character ' literally (case sensitive)
Non-capturing group (?:'\b)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
' matches the character ' literally (case sensitive)
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
' matches the character ' literally (case sensitive)
根据您的要求,一个备选方案(可能不是最有效的)是:
从本质上讲,你一直在使用字符,直到你找到一个以
'
开头的序列,而不是紧跟着一个s或t。你知道吗如果你需要更一般的情况下,你考虑词的边界,然后看看其他答案。你知道吗
^{}
您可以使用这个正则表达式->;
\b\s'(.*?)(?=\'\s|\'$)
你可以在https://pythex.org/上测试它Python代码:
import re user_input = "Play 'My lady's on fire' by Nipsey Hussle Play 'My lady's on fire'" print(re.findall(r"\b\s'(.*?)(?=\'\s|\'$)",user_input))
相关问题 更多 >
编程相关推荐