RegexIssue5EmptyCaptureGroupTest
Tags:elm19-bug
Issue: elm/regex#5
A capture group that matches the empty string is reported as `Nothing`. <https://github.com/elm/regex/issues/5> `Regex.find (.*)` on "" gives the submatch `Nothing` in Elm 0.19.1 (elm/regex 1.0.0); the group did participate and matched "", so it must be `Just ""`. (A group that did not participate, like `(b)?` here, is `Nothing`.)
Results
elm-0.19.1
failran in 68 msMissing pattern: submatches: [[Just ""]] --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. submatches: [[Nothing]] optional: [[Nothing,Nothing]]
elm-0.19.2
failran in 87 msMissing pattern: submatches: [[Just ""]] --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. submatches: [[Nothing]] optional: [[Nothing,Nothing]]
elm-0.19.3
failran in 64 msMissing pattern: submatches: [[Just ""]] --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. submatches: [[Nothing]] optional: [[Nothing,Nothing]]
lamdera-1.5.0
failran in 53 msMissing pattern: submatches: [[Just ""]] --- output --- submatches: [[Nothing]] optional: [[Nothing,Nothing]]
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-regex/RegexIssue5EmptyCaptureGroupTest] in its title.
Source
The -- CHECK: lines give the expected output.
module RegexIssue5EmptyCaptureGroupTest exposing (main)
{-| A capture group that matches the empty string is reported as `Nothing`.
<https://github.com/elm/regex/issues/5>
`Regex.find (.*)` on "" gives the submatch `Nothing` in Elm 0.19.1 (elm/regex 1.0.0); the group did
participate and matched "", so it must be `Just ""`. (A group that did not participate, like
`(b)?` here, is `Nothing`.)
-}
-- TAGS: elm19-bug
-- CHECK: submatches: [[Just ""]]
-- CHECK: optional: [[Just "",Nothing]]
import Html exposing (text)
import Regex
re : String -> Regex.Regex
re =
Regex.fromString >> Maybe.withDefault Regex.never
main =
let
_ =
Debug.log "submatches" (List.map .submatches (Regex.find (re "(.*)") ""))
_ =
Debug.log "optional" (List.map .submatches (Regex.find (re "^(a*)(b)?quot;) ""))
in
text "done"