Skip to Main Content
  • Questions
  • remove + sign from beginning of Phone Numbers

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Megan.

Asked: January 09, 2023 - 9:07 pm UTC

Last updated: January 12, 2023 - 1:44 pm UTC

Version: I don't know.

Viewed 1000+ times

You Asked

Hello!

I have exhausted my search in finding my answer so I am submitting the question!

We are trying to fix incoming data where the phone numbers have a "+" at the beginning. AFter tons of readings, I was able to correct this by using a segment and filter, however, I have been unable to show a successful test through a contact washing machine step. It seems as though what I perceive to be the best option (RegEx Replace) might not be as it looks for patterns, but my excel knowlege of functions tells me I should be able to look for a pattern of a + sign at the beginning of a string of letters.

Here is the information in my "Configure your action" step.

What kind of phone numbers: US & International - I understand I might have to have several conditions

Source: Business Phone
Condition: Business Phone: Contains: +
Action: RegEx Replace
Reg Expression to Find: ????
Reg Expression to Replace: ?????

and Chris said...

I'm unclear exactly which technology you're using - we focus on Oracle SQL & PL/SQL here. Your terminology suggests you're using something else.

That said, part of the issue may be that the plus sign in regular expressions is an operator meaning one or more matches. If you want to match the plus character, you need to escape it. You can do this in Oracle by placing a back slash before it.

I'm also unclear why you need a regular expression. I would just replace plus with null/nothing using standard replace functions.

For example:

with rws as (
  select '+1-123-4567890' phone# from dual union all
  select '+44-1234-567890' phone# from dual
)
  select regexp_replace ( phone#, '^+' ),
         regexp_replace ( phone#, '^\+' ),
         replace ( phone#, '+' )
  from   rws;
  
REGEXP_REPLACE( REGEXP_REPLACE( REPLACE(PHONE#,
--------------- --------------- ---------------
+1-123-4567890  1-123-4567890   1-123-4567890  
+44-1234-567890 44-1234-567890  44-1234-567890 


(The caret character means match the start of the string in regexes. So if a plus appears in the middle of a phone number for some reason, the second expression won't replace it)

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.