user1384205 user1384205 - 1 year ago 60
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 ""


I was able to test this regex (,N,[\d]) in . 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

What am I doing wrong?

Answer Source

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download