Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the implicit definition that converts your <code>Regex</code> into a <code>Parser</code>:</p> <pre><code> /** A parser that matches a regex string */ implicit def regex(r: Regex): Parser[String] = new Parser[String] { def apply(in: Input) = { val source = in.source val offset = in.offset val start = handleWhiteSpace(source, offset) (r findPrefixMatchOf (source.subSequence(start, source.length))) match { case Some(matched) =&gt; Success(source.subSequence(start, start + matched.end).toString, in.drop(start + matched.end - offset)) case None =&gt; Failure("string matching regex `"+r+"' expected but `"+in.first+"' found", in.drop(start - offset)) } } } </code></pre> <p>Just adapt it:</p> <pre><code>object X extends RegexParsers { /** A parser that matches a regex string and returns the Match */ def regexMatch(r: Regex): Parser[Regex.Match] = new Parser[Regex.Match] { def apply(in: Input) = { val source = in.source val offset = in.offset val start = handleWhiteSpace(source, offset) (r findPrefixMatchOf (source.subSequence(start, source.length))) match { case Some(matched) =&gt; Success(matched, in.drop(start + matched.end - offset)) case None =&gt; Failure("string matching regex `"+r+"' expected but `"+in.first+"' found", in.drop(start - offset)) } } } val t = regexMatch("""(\d\d)/(\d\d)/(\d\d\d\d)""".r) ^^ { case m =&gt; (m.group(1), m.group(2), m.group(3)) } } </code></pre> <p>Example:</p> <pre><code>scala&gt; X.parseAll(X.t, "23/03/1971") res8: X.ParseResult[(String, String, String)] = [1.11] parsed: (23,03,1971) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload