I hope you are familiar to Regex. You can use that to match a set of characters in a string, perfect for you.
The test code below is from http://www.xinotes.org/notes/note/1319/ .
import java.util.regex.*;
public class RegExFindAll {
public static void main(String[] args) {
String str = "You can use a Matcher to find all matches to a regular repression";
// find all words starting with m or c, and ends with n or r or s.
// RegEx backslash should be escaped with an additional one.
Pattern p = Pattern.compile("\\b(m|c)\\w*(n|r|s)\\b");
Matcher m = p.matcher(str);
while (m.find()) { // find next match
String match = m.group();
System.out.println(match);
}
// false because regex does not match the whole string
System.out.println("Matches: " + m.matches());
}
}
What does it do? It makes a Matcher object, that matches al the strings containing the letters specified in the code. You should make your own Regex string, so that your values match.
hiddepolen
Posting Whiz in Training
297 posts since Oct 2010
Reputation Points: 82
Solved Threads: 35