如何在python中使用正则表达式捕获两个单词之间的字符?
如何在python中使用正则表达式捕获两个单词之间的字符串?另外,只返回两个单词之间的第一个集合 例如,我想捕捉“Hi”和“Best”之间的所有单词 original_string=“text text words你好,我需要使用正则表达式的帮助,Best Chris more words你好这不是我想要的,Best” 所需的\u string=“在这里,我需要使用正则表达式的帮助,” 我知道您使用的是:(?s)(?您需要调用该方法来返回匹配的字符串:如何在python中使用正则表达式捕获两个单词之间的字符?,python,regex,string,Python,Regex,String,如何在python中使用正则表达式捕获两个单词之间的字符串?另外,只返回两个单词之间的第一个集合 例如,我想捕捉“Hi”和“Best”之间的所有单词 original_string=“text text words你好,我需要使用正则表达式的帮助,Best Chris more words你好这不是我想要的,Best” 所需的\u string=“在这里,我需要使用正则表达式的帮助,” 我知道您使用的是:(?s)(?您需要调用该方法来返回匹配的字符串: >>> import r
>>> import re
>>> original_string = "text text words Hi there, I need help using regular expressions ,Best Chris more words Hi This is not what I want ,Best"
>>> desired_string = re.search("(?s)(?<=Hi).+?(?=Best)", original_string).group()
>>> desired_string
' there, I need help using regular expressions ,'
>>>
>>重新导入
>>>original_string=“text text words你好,我需要使用正则表达式的帮助,Best Chris more words你好这不是我想要的,Best”
>>>所需字符串=重新搜索((?s)(?)?
>>> import re
>>> original_string = "text text words Hi there, I need help using regular expressions ,Best Chris more words Hi This is not what I want ,Best"
>>> desired_string = re.search("(?s)(?<=Hi).+?(?=Best)", original_string).group()
>>> desired_string
' there, I need help using regular expressions ,'
>>>