Simple Groovy replace using regex

I recognize two errors in your code. First one is probably a typo: you are not surrounding the phone number with quotation marks so it’s an integer: 1 + 555 – 555 – 5555 = -5554

Also, you should use replaceFirst since there’s no method replace in String taking a Pattern as first parameter. This works:

def mphone = "1+555-555-5555"
result = mphone.replaceFirst(/^1/, "")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)