我需要匹配所有这些开始标记:
<p>
<a href="foo">
Run Code Online (Sandbox Code Playgroud)
但不是这些:
<br />
<hr class="foo" />
Run Code Online (Sandbox Code Playgroud)
我想出了这个,并希望确保我做对了.我只抓住了a-z.
<([a-z]+) *[^/]*?>
Run Code Online (Sandbox Code Playgroud)
我相信它说:
/,然后我有这个权利吗?更重要的是,你怎么看?
我有一个字符串和一个模式,我想在该字符串中搜索.现在,当我匹配字符串中的模式时,我想知道与我的模式匹配的字符串.
String template = "<P ALIGN=\"LEFT\"><FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT></P>";
String pattern = "<FONT.*>";
Pattern.compile(pattern,Pattern.CASE_INSENSITIVE);
Run Code Online (Sandbox Code Playgroud)
如何找到与模板中的模式匹配的字符串.
即我希望得到<FONT FACE=\"Verdana\" SIZE=\"12\">结果.Java中的正则表达式库提供了哪些方法可以帮助我?
什么是可以匹配的正则表达式,<FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT>并且<LI><FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT></LI>在给定的文本中它不应该是贪婪的.
我试图让正则表达式匹配跨越多行的值.我正在使用re.S标志,但仍然没有结果.有什么想法吗?
这是我正在搜索的文字:
<File id="abc.txt" EngRev="74">
<Identifier id="STRING_ID" isArray="1" goesWith="3027253">
<EngTranslation>"Value 1","Value 2","Value 3","Value 4","Value 5",</EngTranslation>
<LangTranslation filename="abc.txt" key="STRING_ID 0">Value 1</LangTranslation>
<array filename="abc.txt" key="STRING_ID 1">Value 2</array>
<array filename="abc.txt" key="STRING_ID 2">Value 3</array>
<array filename="abc.txt" key="STRING_ID 3">Value 4</array>
<array filename="abc.txt" key="STRING_ID 4">Value 5</array>
</Identifier>
<Identifier id="STRING_ID2" isArray="0" goesWith="3027253">
<EngTranslation>"Value 1"</EngTranslation>
<LangTranslation filename="abc.txt" key="STRING_ID2">Value 1</LangTranslation>
</Identifier>
</File>
Run Code Online (Sandbox Code Playgroud)
这是我用来获取匹配的代码:
def updateToArray(matchobj):
return matchobj.group(0).replace('LangTranslation','array')
outXML = re.sub(r'<Identifier.*?<array.*?</Identifier>', updateToArray, outXML, re.S)
Run Code Online (Sandbox Code Playgroud)