I'm new to regex in Java and I can't figure out how to include named capture groups in an expression. I'm writing a ScrewTurn Image Converter for Confluence's Universal Wiki Converter. This is what I have:
String image = "\\[image(?<align>auto)?\\|\\|{UP\\(((?<namespace>\\w+)\\.)?(?<pagename>[\\w-]+)\\)}(?<filename>[\\w- ]+\\.[\\w]+)\\]";
Pattern imagePattern = Pattern.compile(image, Pattern.CASE_INSENSITIVE);
It's throwing this exception in Pattern.comiple()
:
java.util.regex.PatternSyntaxException: Unknown look-behind group near index 19
\[image(?<align>auto)?\|\|{UP\(((?<namespace>\w+)\.)?(?<pagename>[\w-]+)\)}(?<filename>[\w- ]+\.[\w]+)\]
^
I've used named capture groups like this before in C# (?<namedgroup>asdf)
, but not in Java. What am I missing?
Java doesn't support named captures.
Source: Are Java and C# regular expressions compatible?
It appears Java will only start supporting named capturing groups in version 7: Matcher (SE 6) vs Matcher (SE 7)
Also see: http://java.sun.com/javase/7/docs/api/java/util/regex/Pattern.html#groupname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With