0
Is it possible to turn groups in a regex match into variables?
Let's say I have a string: "15m8s" I want my 2 variables (min, sec) to be 15 and 8 So I have this regular expression: /(\d+)m(\d+)s/ Notice how it has 2 groups. When matched to the string, the matched groups will be: "15" and "8" Is there any way to make a variable out of each group when matched? Answers will be most helpful in JS or Kotlin, but I dont really care which language you are gonna use, I just want to know if it is possible in any language. I know it is a really confusing question and I dont think I'm that good at explaining it so if you dont understand me, feel free to ask questions
5 Answers
+ 1
I have a python example:
https://code.sololearn.com/c9e3Snq93ybN/?ref=app
+ 5
I have a JavaScript example:
use
input.match(/(\d+)m(\d+)s/)
https://code.sololearn.com/WJFPfaTs7afI/?ref=app
+ 1
Ulisses Cruz Thank you! Now I know it's possible. I'll read through the kotlin and js docs to see if I can find anything
+ 1
Oh wow, I already found out how to do it in Kotlin. Thanks for the help
https://code.sololearn.com/c4VBFTbN6MMW/?ref=app
+ 1
CalviŐ˛ thanks!