Python正则表达式查找子字符串和第一个空格之间的所有内容

我有一个字符串string = "radios label="Does the command/question above meet the Rules to the left?" name="tq_utt_test" validates="required" gold="true" aggregation="agg"",我希望能够提取“ name”中的子字符串。所以在这种情况下我想提取“ tq_utt_test”,因为它是里面的子字符串name

我尝试过正则表达式re.findall('name=(.*)\s', string),我认为它会提取子字符串之后name=和第一个空格之前的所有内容。但运行该正则表达式后,它实际上返回了"tq_utt_test" validates="required" gold="true". 所以看起来它返回的是name=最后一个空格之间的所有内容,而不是name=第一个空格之间的所有内容。

有没有办法扭转这个正则表达式,以便它返回第一个空格之后和之前的所有内容 ?name=


月关宝盒
浏览 110回答 1
1回答

qq_花开花谢_0

我只会做re.findall('name=([^ ]*)\s', string)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python