Skip to main content
All Collections💡 Making the Most of YoomRegarding regular expressions
Regular Expressions | Splitting Area Codes and More from Hyphen-Separated Phone Numbers

Regular Expressions | Splitting Area Codes and More from Hyphen-Separated Phone Numbers

Yoom Customer Service avatar
Written by Yoom Customer Service
Updated this week

📝 Overview

With Yoom, data retrieved from sources can be processed using the "Replace" or "Extract" actions in the data transformation process. In this article, we’ll show you how to split and extract area codes and other parts of phone numbers that are separated by hyphens using regular expressions.

📍 Example

  • For landline phones
    Split 03-1234-5678 into “03”, “1234”, and “5678”.

  • For mobile phones
    Split 090-1234-5678 into “090”, “1234”, and “5678”.


🛠️ Extraction Method

1. Extracting the Area Code

  • From the "Data Extraction" actions, select "Extract Data with Regular Expression".

  • Enter the phone number (hyphenated) you wish to extract from. You can also use the output from previous steps.

  • In the "Search (Regular Expression)" field, input:
    0([7-9]0|d|d{2}|d{3}|d{4})(?=-)

  • Run a test.

  • If the test is successful and you confirm there are no spaces in the converted string, enter the output name and save.

2. Extracting the City Code (Middle Number)

  • From the "Data Extraction" actions, select "Extract Data with Regular Expression" again.

  • Enter the phone number (hyphenated) for extraction.

  • In the "Search (Regular Expression)" field, use:
    (?<=-)(.*)(?=-)

  • Run the test.

  • Once the test is successful, and no spaces are found in the result, enter the output name and save.

3. Extracting the Last Four Digits

  • From the "Data Extraction" actions, select "Extract Data with Regular Expression" again.

  • Enter the phone number (hyphenated) to extract the last part.

  • In the "Search (Regular Expression)" field, use:
    (?<=##{{city_code_output}}-)(.*)

  • Run the test.

  • If the test is successful and the string is clean (without spaces), enter the output name and save.

That’s it! 🎉

Now you know how to split and extract area codes, city codes, and the last four digits from hyphen-separated phone numbers.

📚 Related Guides

Related Keywords

Regular expressions, phone number, area code, city code, 4 digits, extraction

Did this answer your question?