简体   繁体   中英

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. 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) .

The group takes the "Group from the last match". But as there was no match yet, you found nothing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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