0

I faced the following problem. My string contains math expression. For example like this:

5+|-2|

And I need to convert it to

5+Math.abs(-2)

I can do it with loop (check if the vertical bar is met the first time, replace it on the Math.abs(, second - replace on the )). But is there any way to do it with Regex in Kotlin? Thanks in advance for any help!

  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/questions/4736) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Oct 05 '20 at 21:31

0 Answers0