Lookahead regex produces unexpected group
- by Ivan Yatskevich
I'm trying to extract a page name and query string from a URL which should not contain .html
Here is an example code in Java:
public class TestRegex {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("/test/(((?!\\.html).)+)\\?(.+)");
Matcher matcher = pattern.matcher("/test/page?param=value");
System.out.println(matcher.matches());
System.out.println(matcher.group(1));
System.out.println(matcher.group(2));
}
}
By running this code one can get the following output:
true
page
e
What's wrong with my regex so the second group contains the letter e instead of param=value?