Java examples for Regular Expressions:Pattern
That includes upper- and lowercase letters, digits, and the underscore. For example:
The following pattern matches two groups of word characters separated by a non-word character.
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Pattern pattern = Pattern.compile("\\w\\w\\w\\W\\w\\w\\w"); Matcher matcher = pattern.matcher("abc def"); if (matcher.matches()) System.out.println("Match."); else/* w ww . j av a2 s . co m*/ System.out.println("Does not match."); } }