user1384205
user1384205

Reputation: 1291

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?

Upvotes: 0

Views: 100

Answers (1)

chengpohi
chengpohi

Reputation: 14217

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

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

Upvotes: 2

Related Questions