Is there a way in Kotlin to match a regex until so...
# announcements
v
Is there a way in Kotlin to match a regex until some character without creating a substring? Like
find(input, 50)
to search after character 50 but so that only until character 50 is tried to match. And what is the difference between
slice
,
substring
and
subSequence
?
e
You can add it to the Regex:
^.{50}(your-match)
v
That's not fitting the requirement
For that I could just use
find(input, 50)
e
Sorry, I think didn't understand the requirement then
I thought you wanted something that does not create a substring, and adding it to the Regex fulfills this requirement
v
"lorem ipsum dolor sit amet" and I want the regex only matched against "lorem ipsum dolor"
find(input, 50)
also does not create a substring and does exactly the same as your suggestion
But that would match against "sit amet" which is not what I want
e
Got it
I guess with Regex and without a substring there's no way
If you are on Kotlin/JVM, of course...
Pattern.compile("your-pattern").matcher(stringToMatch).region(0, 50).find()
v
Ah nice, didn't know that method, thanks, that will probably do if there is no Kotlin-specific way
🤘 1
e
I didn't know about it either, so we both learned something today 😁
❤️ 1