user1384205 user1384205 - 1 month ago 6
Scala Question

Regex to match number after a defined text

I have the following text to apply regex on, where I want to replace all occurences of ,N, to be replaced by ""

1,N,1,XROW30_!@#@!#_1231_asdsad

I was able to test this regex (,N,[\d]) in http://regexr.com/ . The expression seems to correctly match the text.

However when I use it on my program, the regex does not work

val regN = """(,N,[\d])"""

...
.map (row => row.replace(regN, ""))


The end result im looking for is this
1,XROW30_!@#@!#_1231_asdsad

What am I doing wrong?

Answer

String.replace this method will not replace by regex: String.replace

you should use String.replaceFirst or String.replaceAll:String.replaceFirst String.replaceApp