1

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));
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
William Falcon
  • 9,813
  • 14
  • 67
  • 110
  • 6
    Don't use Regex to parse HTML/XML. Examples [here](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – Walls Apr 18 '13 at 20:37
  • "Where am I going wrong?" How do you know you are going wrong? Is there an error message? Does your code compile? Does it run, but do something you don't expect? – Richard JP Le Guen Apr 18 '13 at 20:38

1 Answers1

3

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.

Itchy
  • 2,263
  • 28
  • 41