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,
1 2 3 |
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),
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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