Colton Idle
05/05/2023, 4:00 PMsubstringAfter()
What would the kotlin regex based alternative to substringAfter("abc")
be for example?eygraber
05/05/2023, 4:13 PM.*abc(.*)
and then get the first groupeygraber
05/05/2023, 4:16 PMval match = Regex(".*abc(.*)").find("<your string here>")
if(match != null && match.groupValues.size >= 2) {
match.groupValues[1]
}
Gleb Minaev
05/05/2023, 4:19 PM(?<=abc).*
for substring after abc
. (At least on JVM.)
UPD. It works on JS, as well.Klitos Kyriacou
05/05/2023, 4:20 PMfun String.reinventedSubstringAfter(delimiter: String) =
"(?<=$delimiter).*".toRegex().find(this)?.value ?: this
(assuming the delimiter doesn't contain any special characters).
You might want to drop the ?: this
at the end, if you want it to return null if it doesn't find the substring. I put it in there to make it compatible with the standard substringAfter
which returns the original string.Colton Idle
05/05/2023, 4:22 PMfun findThing(chars: String, line: String): String? {
val matcher = Pattern.compile(".*$chars(.*)").matcher(line)
if (matcher.matches()) {
return matcher.group(1)
}
return null
}
Colton Idle
05/05/2023, 4:23 PMColton Idle
05/05/2023, 4:23 PMhallvard
05/05/2023, 4:56 PMAlejandro Rios
05/05/2023, 5:25 PMColton Idle
05/05/2023, 5:43 PM