xenomachina
03/10/2017, 6:53 PMmfulton26
03/10/2017, 7:47 PMxenomachina
03/10/2017, 8:40 PMxenomachina
03/10/2017, 8:43 PM"foo456bar", the Regex "\\d+" and the position "3", I'd like it to give me a match on the substring "456".xenomachina
03/10/2017, 8:44 PMlookingAt 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 == startIndexmfulton26
03/10/2017, 8:53 PMRegex 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.xenomachina
03/10/2017, 9:17 PMPattern and Matcher, but was hoping for a more "Kotlin-y" way of doing it.xenomachina
03/10/2017, 9:17 PMnkiesel
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