Take the 2-minute tour ×

I'm sure this is definitely a simple and stupid question, but I can't figure out how to remove leading "+1" from a string using re module's sub(). I've been trying these

import re


but they all return the same original string. Could someone help me point out the obvious mistake I'm making? Thank you.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Use \ for escaping +, not /

share|improve this answer
Yes! I forgot to try ``. Thank you. It works now. :) –  user1330974 Jun 22 '13 at 0:31
add comment

You dont need regex to do this, if you always just want to remove the first two letters you can just do this

number = "+1585123456"
number = number[2:] 
share|improve this answer
That's also right. Thank you. –  user1330974 Jun 22 '13 at 0:54
add comment

Your Answer


