Substring matching with regular expressions
Hi all,
I'm having one heck of a time with regular expressions and I'm hoping that someone can lend me a hand. What I'm trying to do is look for a particular substring within a string using a pattern. Here's my code:
import java.util.regex.*;
publicclass RegExTest{
publicstaticvoid main(String[] args){
String testStr ="This 9 XX is my test string.";
Pattern pattern = Pattern.compile("\\b\\d+\\sXX\\b");
Matcher matcher = pattern.matcher(testStr);
System.out.println("Matches: " + matcher.matches());
}
}
So what I'm trying to do is find substrings that start with a number, followed by whitespace, followed by XX, all within a word boundary. Unfortunately this is not working for me and I don't know why. Can anyone help?

