I'm debugging some Regex Builder code in my Playground. I run the following piece code:
let timeMatchWithout = possibleTime.firstMatch(of: timeWithoutSec)
and I get this error message:
Regex.Match optional storedCapture contains no some
What could this possibly mean? contains no some???
Here is a more complete snippet, if this helps:
let hourRef = Reference<Substring>()
let minuteRef = Reference<Substring>()
let hourReg = Regex {
ChoiceOf {
Capture(as: hourRef) {
One(.digit)
One(.digit)
}
Capture(as: hourRef) {
One(.digit)
}
}
}
let minuteReg = Regex {
ChoiceOf {
Capture(as: minuteRef) {
One(.digit)
One(.digit)
}
Capture(as: minuteRef) {
One(.digit)
}
}
}
let ampmRef = Reference<Substring>()
let ampmReg = Regex {
Capture(as: ampmRef) {
ZeroOrMore {
ChoiceOf {
One("am")
One("pm")
One("a.m.")
One("p.m.")
}
}
} /* transform: {
$0.lowercase
} */
}.ignoresCase()
let timeWithoutSec = Regex {
hourReg
One(":")
minuteReg
ZeroOrMore(.whitespace)
ampmReg
}.ignoresCase()
let possibleTime = "10:20 AM"
let timeMatchWithout = possibleTime.firstMatch(of: timeWithoutSec)
The last line produces the error message. Thanks for the help.
Note the removed transform: on the ampmReg definition. If that is included the compiler times out as noted in my previous post, yesterday.