Latest web development tutorials

Javaは()メソッドに一致します

JavaのStringクラス JavaのStringクラス


マッチ()メソッドは文字列が与えられた正規表現に一致するかどうかを検出するために使用されます。

この方法は全く同じで、次の式の形でstr.matches(正規表現)の結果と呼ばれています。

Pattern.matches(regex, str)

文法

public boolean matches(String regex)

パラメータ

  • 正規表現-文字列にマッチする正規表現。

戻り値

文字列が与えられた正規表現と一致した場合、それはtrueを返します。

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(.*)"));
	}
}

上記プログラムの実行結果:

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

JavaのStringクラス JavaのStringクラス