xenomachina
03/10/2017, 6:53 PMmfulton26
03/10/2017, 7:47 PMxenomachina
03/10/2017, 8:40 PM"foo456bar"
, the Regex "\\d+"
and the position "3", I'd like it to give me a match on the substring "456".lookingAt
to tell if my Matcher matches at the start of the region.mfulton26
03/10/2017, 8:50 PMregex.toPattern().matcher(input).region(startIndex, input.length).lookingAt()
- regex.find(input, startIndex)?.range?.start == startIndex
Regex
and convert it to a Pattern
and use a Matcher
which you are already familiar with or you can use find
with a check on the returned kotlin.text.MatchResult
.xenomachina
03/10/2017, 9:15 PMlookingAt
in terms of behavior, but performance would be much worse, since it's going to be constantly trying to match stuff I'm just going to throw away.Pattern
and Matcher
, but was hoping for a more "Kotlin-y" way of doing it.nkiesel
03/11/2017, 12:16 AMfun main(args: Array<String>) {
println("Hello, world!")
val input = "foo456bar"
val p1 = Regex("\\d+")
println(p1.find(input, 3)?.range?.first == 3)
val p2 = Regex(".{3}\\d+.+")
println(p2.matches(input))
}
mfulton26
03/12/2017, 1:07 AM...?.start == startIndex
in that find
will continue searching the entire string for a match where the goal is to only match at that index and avoid the performance impact of searching the entire string unnecessarily.nkiesel
03/16/2017, 4:49 AMp2
approach would not do that because it's anchored but needs to skip over {n}
read characters every time. I would assume that this is optimized to a seek, and thus comes pretty close to what you wantmfulton26
03/17/2017, 12:38 PMxenomachina
03/21/2017, 10:08 PM