と一致する正規表現パターンを作成したいのですが、パターン文字列がでない場合は、の文字列をテスト文字列または入力文字列に続けてください。ここに私が試したものがあります:特定のpositonでのみ文字列に一致するJava正規表現パターンを作成するには?
Pattern p = Pattern.compile("google.com");//I want to know the right format
String input1 = "mail.google.com";
String input2 = "mail.google.com.co.uk";
Matcher m1 = p.matcher(input1);
Matcher m2 = p.matcher(input2);
boolean found1 = m1.find();
boolean found2 = m2.find();//This should be false because "google.com" is followed by ".co.uk" in input2 string
助けていただければ幸いです!
文字列の最後にマッチを結びつけるために '$'を使います。 –