Java examples for Regular Expressions:Match
String match with regular expression
public class Main { private String jaText = "this is a test "; private String enText = "The fat cat sat on the mat with a brown rat."; private String enRegEx = "^The \\w+ cat.*"; private String jaRegEx = ".*.*"; private String jaRegExEscaped = ".*\u6587\u5B57.*"; public Main() { boolean found = false; found = enText.matches(enRegEx);// w w w. j a v a2 s .co m if (found) { System.out.printf("Matches %s.\n", enRegEx); } found = jaText.matches(jaRegEx); if (found) { System.out.printf("Matches %s.\n", jaRegEx); } found = jaText.matches(jaRegExEscaped); if (found) { System.out.printf("Matches %s.\n", jaRegExEscaped); } } }