Scala regex Named Capturing Groups

Posted by Brent on Stack Overflow See other posts from Stack Overflow or by Brent
Published on 2010-06-12T18:17:34Z Indexed on 2010/06/12 18:22 UTC
Read the original article Hit count: 427

Filed under:
|

In scala.util.matching.Regex trait MatchData I see that there support for groupnames (Named Capturing Groups)

But since Java does not support groupnames until version 7 as I understand it, Scala version 2.8.0.RC4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6. gives me this exception:

scala> val pattern = """(?<login>\w+) (?<id>\d+)""".r
java.util.regex.PatternSyntaxException: Look-behind group does not have an obvio
us maximum length near index 11
(?<login>\w+) (?<id>\d+)
           ^
        at java.util.regex.Pattern.error(Pattern.java:1713)
        at java.util.regex.Pattern.group0(Pattern.java:2488)
        at java.util.regex.Pattern.sequence(Pattern.java:1806)
        at java.util.regex.Pattern.expr(Pattern.java:1752)
        at java.util.regex.Pattern.compile(Pattern.java:1460)

So the question is Named Capturing Groups supported in Scala? If so any examples out there?

If not I might look into the Named-Regexp lib from clement.denis.

© Stack Overflow or respective owner

Related posts about regex

Related posts about scala