Regular Expression
String
The String class contains support for regular expressions:
Boolean matches;
matches = string.matches(regex);
The following methods support regular expressions:
matches
split
replaceFirst
replaceAll
Regex Model
The JDK includes classes for regular expressions. These are the Pattern and the Matcher.
The Pattern contains the regular expression, while the Matcher is used to apply said regular expression.
String numbers;
Pattern pattern;
Matcher matcher;
String text;
text = "123";
numbers = "[0-9]*";
pattern = Pattern.compile(numbers);
matcher = pattern .matcher(text);
Now you can work with the matcher.
Boolean matches;
matches = mat.matches();
Last updated
Was this helpful?