Latest web development tutorials

Java matches () method

Java String class Java String class


matches () method is used to detect whether the string matches the given regular expression.

This method is called the str.matches (regex) results in the form of the following expression in exactly the same:

Pattern.matches(regex, str)

grammar

public boolean matches(String regex)

parameter

  • regex - regular expression matching string.

return value

When the string matches the given regular expression, it returns true.

Examples

public class Test {
	public static void main(String args[]) {
		String Str = new String("www.w3big.com");

		System.out.print("返回值 :" );
		System.out.println(Str.matches("(.*)w3big(.*)"));
		
		System.out.print("返回值 :" );
		System.out.println(Str.matches("(.*)google(.*)"));

		System.out.print("返回值 :" );
		System.out.println(Str.matches("www(.*)"));
	}
}

The above program execution results:

返回值 :true
返回值 :false
返回值 :true

Java String class Java String class