The following should work say if you want to change the area code from 406
to 302
s/\b406(\d{7})\b/302$1/g
Basically, it looks for a 10 digit number beginning with 406, captures the
last 7 digits, and replaces it with 302 and the same captured 7 digits.
I've treated it is separated by a word boundary, but if that isn't the case, you
may want to remove the \b and replace with whatever separator you do use between
your phone number and the rest of your data. This will not work if you
have numbers in the format (406) 555-1212 or 302-555-1212 or any other but
straight up 10 digits, so you may want to check for the other situations with
like a
s/\b\(?406\)?
?-?(\d{3})-?(\d{4})\b/302$1$2/g
where all those confusing question marks are simply looking for 0 or 1
instances of the other usual phone number formats.
|
- How to search & replace only the first 3 digitsof a 10... Mike Charles
- Re: How to search & replace only the first 3 digi... Kristina Nairn
- Re: How to search & replace only the first 3 digi... Kristina Nairn
- RE: How to search & replace only the first 3 digi... Timothy Johnson