Java RegEx Pattern not matching (works in .NET)
- by CDSO1
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");
}
}