-
潇潇雨雨
这也可以,而且很简单str = "review: I love you very much... reviewer:jackson review: I hate you very much... reviewer:madden review: sky is pink and i ... reviewer: tom"matches = re.findall('review:(.+?)\.\.\.', str)
-
德玛西亚99
使用re.findall(r'\breview:\s*(.*?)\s*\.\.\.', string)见证明。蟒蛇测试:import reregex = r"\breview:\s*(.*?)\s*\.\.\."string = "review: I love you very much... reviewer:jackson review: I hate you very much... reviewer:madden review: sky is pink and i ... reviewer: tom"print ( re.findall(regex, string) )输出:['I love you very much', 'I hate you very much', 'sky is pink and i']请注意,r"..."表示原始字符串文字的前缀"\b"不是单词边界,而是r"\b"。解释NODE EXPLANATION-------------------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char-------------------------------------------------------------------------------- review: 'review:'-------------------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible))-------------------------------------------------------------------------------- ( group and capture to \1:-------------------------------------------------------------------------------- .*? any character except \n (0 or more times (matching the least amount possible))-------------------------------------------------------------------------------- ) end of \1-------------------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible))-------------------------------------------------------------------------------- \.\.\. '...'--------------------------------------------------------------------------------
-
largeQ
您可以使用以下利用前瞻的模式:(?<=review:\s).*?(?=\.\.\.)inp = "review: I love you very much... reviewer:jackson review: I hate you very much... reviewer:madden review: sky is pink and i ... reviewer: tom"matches = re.findall(r'(?<=review:\s).*?(?=\.\.\.)', inp)print(matches)
-
当年话下
re.findall与模式一起使用\breview:\s*(.*?)\.\.\.\s*(?=\breviewer:|$):inp = "review: I love you very much... reviewer:jackson review: I hate you very much... reviewer:madden review: sky is pink and i ... reviewer: tom"matches = re.findall(r'\breview:\s*(.*?)\.\.\.\s*(?=\breviewer:|$)', inp)print(matches)这打印:['I love you very much', 'I hate you very much', 'sky is pink and i ']
-
慕虎7371278
\对不起,我忘了在前面 添加.正确的是: re.findall("review:\b?(.*)\.\.\.",string)而这一次,很重要