to achieve this, you need 2 java classes: Matcher and Pattern.
you have to build up the Pattern object and call on it the method which gives you the matcher instance.
// in the beginning, import necessary classes
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatches
{
public static void main( String args[] ){
// this is the array with urls to check
String [] urls = {"https://google.com", "www.google.com"};
// now, let's check if strings are matching
for (int i = 0; i < urls.length; i++) {
// string to be scanned to find the pattern
String url = urls[i];
String pattern = "google.com";
// create a Pattern object
Pattern p = Pattern.compile(pattern);
// now, create Matcher object.
Matcher m = p.matcher(url);
// let's check if something was found
if (m.find()) {
System.out.println("Found value: " + url);
} else {
System.out.println("NO MATCH");
}
}
}
}
you can add to the array all the urls you want the pattern to check!