Java RegEx Pattern not matching (works in .NET)

Posted by CDSO1 on Stack Overflow See other posts from Stack Overflow or by CDSO1
Published on 2010-04-27T19:10:40Z Indexed on 2010/04/27 19:13 UTC
Read the original article Hit count: 381

Filed under:
|
|

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");     
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about regex