简体   繁体   English

正则表达式找不到匹配项

[英]Regular expression not finding a match

I am trying to match the word Salvage in this string, but the code is not picking it up. 我试图在这个字符串中匹配单词Salvage,但代码并没有把它拿起来。 Where am I going wrong? 我哪里错了?

//String to match
String titleString = "<td><i><a href="/page/Vengeance2" title="Salary">Salvage</a></i></td>";

System.out.println(titleString);

//Template
String template = ">(.*)</a>";

//
Pattern p=Pattern.compile(template);
Matcher matcher = p.matcher(titleString);

System.out.println(matcher.group(1));

Try to put a matcher.find() just before the matcher.group(1) . 尝试将matcher.find()就在之前matcher.group(1)

The group takes the "Group from the last match". 该组采用“最后一场比赛的小组”。 But as there was no match yet, you found nothing. 但由于还没有比赛,你什么都没发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM