Skip to content

Non-capturing group not working #383

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
hissashirocha opened this issue May 12, 2021 · 0 comments
Open

Non-capturing group not working #383

hissashirocha opened this issue May 12, 2021 · 0 comments

Comments

@hissashirocha
Copy link

hissashirocha commented May 12, 2021

I'm testing Scala Parser Combinators but for some reason I can't make non-capturing group work.

When I run the following, it works the way I want, returning only 003:

val cycle = """(?:CLEARING\sCYCLE\s)([0-9]{3})""".r

"CLEARING CYCLE 003" match {
  case cycle(a) => println(a)
}

But when I try using RegexParsers, I get the whole string CLEARING CYCLE 003 instead of just the numbers:

class TestParser extends RegexParsers {
  def cycle: Parser[String] = """(?:CLEARING\sCYCLE\s)([0-9]{3})""".r
}

object Test extends TestParser {
   def parse(text: String) {
     parse(cycle, text) match {
        case Success(matched,_) => println(matched)
        case Failure(msg,_) => println(s"FAILURE: $msg")
        case Error(msg,_) => println(s"ERROR: $msg")
     }
   }
}

Test.parse("CLEARING CYCLE 003")

Am I missing something or is it an issue?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant