How to use Regular Expression in Kotlin? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to use Regular Expression in Kotlin?

I know I have to create a pattern in Regular Expression Syntax and then I can match it with the actual string. But I want to extract the match from the String and save it to a variable. How can I do that in Kotlin?

28th Feb 2020, 5:53 PM
Plaban Kr. Mondal
Plaban Kr. Mondal - avatar
5 Answers
+ 6
This gives an example of getting the range which can be used to generate a substring. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex/find.html
28th Feb 2020, 6:40 PM
John Wells
John Wells - avatar
+ 4
You can use (C|c) to match both cap and lower. There is also a flag to make search ignore case.
28th Feb 2020, 8:56 PM
John Wells
John Wells - avatar
+ 1
https://code.sololearn.com/cFywKzFp2mVS/?ref=app Can you tell me why this code is throwing a null pointer exception
28th Feb 2020, 7:50 PM
Plaban Kr. Mondal
Plaban Kr. Mondal - avatar
+ 1
Ok I got it!! Regex is Case sensitive
28th Feb 2020, 8:04 PM
Plaban Kr. Mondal
Plaban Kr. Mondal - avatar
0
Did I put a wrong Regular Expression Syntax ?????
28th Feb 2020, 7:51 PM
Plaban Kr. Mondal
Plaban Kr. Mondal - avatar