Skip to content

Non-capturing group not working #383

Open
@hissashirocha

Description

@hissashirocha

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions