14 May String matches() method in Java
The boolean matches(String regex) method in Java tells whether or not this string matches the given regular expression.
Syntax
Let us see the syntax,
boolean matches(String regex)
Parameters
Let us see the parameters,
- regex − the regular expression with which the string is matched
Example
The following is an example of matches(String regex),
public class StudyopediaDemo {
public static void main(String args[]) {
String message = new String("Studyopedia provides free learning content!");
System.out.println("String: "+message);
// True
System.out.println(message.matches("Studyopedia(.*)"));
// False
System.out.println(message.matches("(.*)Studyopedia"));
}
}
Output
The following is the output,

No Comments