Given the following expression:
"^.*" + "http://www\\.xyz\\.gov/class/"+ "([0-9]+)";
I would expect that if i pass the string "http://www.xyz.gov/class/17950142?dopt=abstract" it should match to everything up to the ? character.
Why does it not do that in the following code snippet?
public class RegexTester {
private final static String EPR_TYPE_1 = "http://www\\.xyz\\.gov/class/";
public static void main(String args[]){
String testRegex = "^.*" + EPR_TYPE_1 + "([0-9]+)";
String testString = "http://www.xyz.gov/class/17950142?dopt=abstract";
Pattern PATTERN = Pattern.compile(testRegex, Pattern.CASE_INSENSITIVE);
Matcher m = PATTERN.matcher(testString);
if(m.matches()) {
System.out.println(m.group(1));
}else{
System.out.println("No match");
}
}
}
I tried the same expression and string in an online regex tester and it seems to work See example here RegExr