我有一个输入:
</name> rahul is nice guy <version=name> previous name is manoj </version> and cool </s>
我正在使用正则表达式
re.search(r'(</name>([a-z0-9]+)(?!<version>(.*?)</version>)([a-z0-9]+)</s>)', line, re.M|re.I)
我的输出应该是:
rahul is nice guy and cool
它与模式不匹配,我试图在'版本'标签之间省略单词,有人可以告诉我哪里出错了吗?
用python编写。
答案 0 :(得分:3)
此模式匹配:
</name>([a-z0-9 ]+)<version=name>(.*?)</version>([ a-z0-9]+)</s>
请注意空格[a-z0-9 ]
,并记下您忘记的字符=name
。
当然,你必须参加第一场比赛和第三场比赛。
如果是python - 获取文本而不是版本名称中的文本:
Matches = re.findall(r'</name>([a-z0-9 ]+)<version=name>(.*?)</version>([ a-z0-9]+)</s>', line, re.M|re.I)
FinalText = Matches[0] + Matches[2]
答案 1 :(得分:0)