Vivek Modi
05/04/2021, 1:31 PMval index = "Hey! How are you men? How you doing"
i want to search you doing from the above string, but i want y index from the word you. I did some code to find index but I am unable to find it.
fun main(vararg args: String) {
val inputString = "Hey! How are you men? How you doing"
val regex = "you doing".toRegex()
val match = regex.find(inputString)!!
println(match.value)
println(match.range)
}
Luke
05/04/2021, 2:02 PMVivek Modi
05/04/2021, 2:03 PMVivek Modi
05/04/2021, 2:03 PMLuke
05/04/2021, 2:06 PM"(?<= )\\w+ \\w+\\z"
which works with your example, but it matches words with numbers and underscore as wellVivek Modi
05/04/2021, 2:07 PMLuke
05/04/2021, 2:07 PM\\w
with [a-zA-Z]
Luke
05/04/2021, 2:09 PM(?<= )
, matches a space, but will not be part of the resulting match. It just looks that the preceding character is a spaceLuke
05/04/2021, 2:10 PM\\w
matches a letter (caps or not), a number or an underscore. The +
after means there can be more than oneVivek Modi
05/04/2021, 2:10 PMLuke
05/04/2021, 2:10 PM\\z
matches the end of a stringTom Hermann
05/04/2021, 2:48 PMTom Hermann
05/04/2021, 2:48 PMVivek Modi
05/04/2021, 3:07 PMVivek Modi
05/04/2021, 3:07 PM