Java String: matches() Method
public boolean matches(String regex)
The matches() method tells whether or not this string matches the given regular expression.
An invocation of this method of the form str.matches(regex) yields exactly the same result as the expression
Pattern.matches(regex, str)
Java Platform: Java SE 8
Syntax:
matches(String regex)
Parameter:
Name | Description | Type |
---|---|---|
regex | the regular expression to which this string is to be matched | boolean |
Return Value: true if, and only if, this string matches the given regular expression.
Return Value Type: boolean
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
Example: Java String matches(String regex) Method
The following example shows the usage of java String() method.
Output:
Regex: (.*)quick brown fox(.*) true Regex: (.*)quick brown wolf(.*) false
Java Code Editor :
Previous:length Method
Next:offsetByCodePoints Method