I’ve been reading through regex and I thought this would work but it doesn’t seem to want to work. All I need to do is strip the leading 1 off a phone number if it exists.
So:
def mphone = 1+555-555-5555
mphone.replace(/^1/, "")
Shouldn’t this output +555-555-5555?
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
replaceFirstsince there’s no methodreplacein String taking a Pattern as first parameter. This works: