Below is an example that is producing an exception in Java (and not matching the input). Perhaps I misunderstood the JavaDoc, but it looks like it should work. Using the same pattern and input in C# will produce a match.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String pattern = "aspx\\?uid=([^']*)";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher("id='page.aspx?uid=123'");
System.out.println(m.groupCount() > 0 ? m.group(1) : "No Matches");
}
}
EDIT: I should note the JavaDoc says the following about Matcher.groupCount
Any non-negative integer smaller than or equal to the value returned by this method is guaranteed to be a valid group index for this matcher.