I'm having a simple Java Regex issue. I'm trying to get to identigy any pattern that matches the character 'p' + any number, meaning, p1, p10, p100 and so on.
By checking the actual regex at http://regexr.com/, the actuall expression i want is /(p\d+)/
While I have no issues using regex with JavaScript, I'm having a world of trouble with Java.
This is the part of the code that I'm actually trying to get to work properly:
boolean inBounds = (arrayPair.length == 2);
String c = ("\(p\d+)\");
Pattern p = Pattern.compile(c);
Matcher m = p.matcher(arrayPair[0]);
boolean b = m.matches();
This particular string gives me a invalid escape character, according to this (Invalid escape sequence) I should use double slashes, meaning the line should change to
String c = ("\\(p\\d+)\\");
This gives me a Unmatched closing ')' near index 5 \(p\d+)\" error.
So, I went back to http://regexr.com/ and realized I could write the expression as /p\d+/
So I went back to Java and tried
String c = ("\\p\\d+\\");
This gives a Unknown character property name {\} near index 2 \p\d+\
And it points to the '\' of the 'p\d' part.
Sooooo in another stackoverflow answer somebody mentioned I should use \\ instad of \ for d.
String c = ("\\p\\\\d+\\");
Which lead me to the error Unknown character property name {} near index 2 \p\d+\
Am I missing something here? I'm starting to go crazy about RegEx implementations...