Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 855775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:07:54+00:00 2026-05-15T08:07:54+00:00

In scala.util.matching.Regex trait MatchData I see that there support for groupnames , I thought

  • 0

In scala.util.matching.Regex trait MatchData I see that there support for groupnames , I thought that this was related to (Regex Named Capturing Groups)

But since Java does not support groupnames until version 7 as I understand it (ref), Scala version 2.8.0 (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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:07:55+00:00Added an answer on May 15, 2026 at 8:07 am

    I’m afraid that Scala’s named groups aren’t defined the same way. It’s nothing but a post-processing alias to unnamed (i.e. just numbered) groups in the original pattern.

    Here’s an example:

    import scala.util.matching.Regex
    
    object Main {
       def main(args: Array[String]) {
          val pattern = new Regex("""(\w*) (\w*)""", "firstName", "lastName");
          val result = pattern.findFirstMatchIn("James Bond").get;
          println(result.group("lastName") + ", " + result.group("firstName"));
       }
    }
    

    This prints (as seen on ideone.com):

    Bond, James
    

    What happens here is that in the constructor for the Regex, we provide the aliases for group 1, 2, etc. Then we can refer to these groups by those names. These names are not intrinsic in the patterns themselves.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why there is a match here: scala> \bdog\b.r res65: scala.util.matching.Regex = \bdog\b scala> res65.findFirstIn(
I'm still a Scala noob, and this confuses me: import java.util.regex._ object NumberMatcher {
First, I was like cool ... scala> var nameRE = \W*(\w+)\W+(\w+)\W*.r nameRE: scala.util.matching.Regex =
scala> val p = ab|ba|(ab)*a|(ba)*b.r p: scala.util.matching.Regex = ab|ba|(ab)*a|(ba)*b scala> val m = p.pattern.matcher
Scala programmer should have known that this sort of writing : class Person{ var
I have this class in Scala: object Util { class Tapper[A](tapMe: A) { def
In the Scala shell I did this: import java.util._ import scala.collection.JavaConversions._ val t: SortedMap[String,Int]
scala> import java.util.Properties import java.util.Properties scala> trait Foo extends Properties defined trait Foo scala>
Starting with Scala version 2.9 there exists a handy converter to convert from java.util.List
How to solve this using scala Actors: I have a program that finds out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.