The matches() method is used to check if the string stated matches the specified regular expression in the argument or not.
Method Definition: Boolean matches(String regex)
Return Type: It returns true if the string matches the regular expression else it returns false.
Example #1:
// Scala program of int matches() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying matches method val result = "Preeti".matches(".*i") // Displays output println(result) } } |
chevron_right
filter_none
Output:
true
So, here the regular expression matches the string stated. So, it returns true.
Example #2:
// Scala program of int matches() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying matches method val result = "Preeti".matches(".i.*") // Displays output println(result) } } |
chevron_right
filter_none
Output:
false
Recommended Posts:
- Scala String indexOf(String str) method with example
- Scala String startsWith(String prefix, int toffset) method with example
- Scala String lastIndexOf(String str, int fromIndex) method with example
- Scala String indexOf(String str, int fromIndex) method with example
- Scala String regionMatches(int toffset, String other, int offset, int len) method with example
- Scala String lastIndexOf(String str) method with example
- Scala String startsWith(String prefix) method with example
- Scala String split(String regex, int limit) method with example
- Scala String contentEquals() method with example
- Scala String substring(int beginIndex, int endIndex) method with example
- Scala String subSequence() method with example
- Scala String equalsIgnoreCase() method with example
- Scala String endsWith() method with example
- Scala String compareToIgnoreCase() method with example
- Scala String charAt() method with example
- Scala String equals() method with example
- Scala String compareTo() method with example
- Scala String getBytes() method with example
- Scala String hashCode() method with example
- Scala String indexOf() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

