Q:

Search Wildcard('<', '>'), count it and get the position in java

I want to search Wildcard('<', '>') in a string, count them and get their positions in java. My string is like below

Peter <5554>, John <5556>,

which function should I use? Thank you.

A:

You  should use Pattern and Matcher:
Pattern pattern = Pattern.compile("<[^>]*>");
Matcher matcher = pattern.matcher("Peter <5554>, John <5556>,");
while (matcher.find()) {
   System.out.println("index="+matcher.start()+" - "+matcher.group());
}

Output:
index=6 - <5554>
index=19 - <5556>

