Blog > Post

RegEx: How to Extract All Phone Numbers from Strings

Tuesday, March 02, 2021

If you want to extract phone numbers by using Regular Expression but don’t know how to write Regular Extraction, the article may help you with this.

It could be multiple phone numbers in a single large string and these phone numbers could come in a variety of formats. Here is an example of the file format:


  • (021)1234567
  • (123) 456 7899
  • (123).456.7899
  • (123)-456-7899
  • 123-456-7899
  • 123 456 7899
  • 1234567899
  • 0511-4405222
  • 021-87888822
  • +8613012345678
  • ...


Read Octoparse customer story: Turn web pages into sales leads


What is the easiest way to extract phone numbers like these? The regular expression is very hard to learn if you don’t have any programming knowledge. In this article, I’ll introduce you a great Regular Expression tool to help you directly generate Regular Expressions and match all the phone numbers quickly.

Regular Expression to Match Email Addresses from strings

First, try your best to find the common character that each phone number starts with and ends with. For example, for the targeted text above, I find its source code, shown below.


<p >Here is an example of file format </p>


  <li>(021)1234567 </li>

  <li>(123) 456 7899 </li>

  <li>(123).456.7899 </li>

  <li>(123)-456-7899 </li>

  <li>123-456-7899 </li>

  <li>123 456 7899 </li>

  <li>1234567899 </li>

  <li>0511-4405222 </li>

  <li>021-87888822 </li>

  <li>+8613012345678 </li>

  <li>... </li>



We can see that each phone number starts with <li> and ends with </li>. And we can use the RegEx Tool in Octoparse to quickly extract all phone numbers. 

       1. Run Octoparse and open the RegEx Tool.

       2. Copy and paste the source code in the "Source Text" box.

           Then select "Start With" option and enter "<li>".  

       3. Next, select "End With" option and enter "</li>".

           Don’t forget to select the "Match All" option.

       4. Select "Generate" and "Match" option one by one.

It’s done. All the matched phone numbers are listed in the green box.




Note that if you can’t find out the common character that each phone number starts with and ends with, you cannot extract all phone numbers at a time. If so, you need a special Regular Expression for each format of phone numbers.

Here, I wrote down two additional Regular Expressions for two formats of phone numbers.


Regular Expression:


Match: 0511-4405222 | 021-87888822




Regular Expression:


Match: (021)1234567 | (0411)123456 | (000)000000 |(123)1234567




More functions on Octoparse Regular Expression Tool


Artículo en español: RegEx: Cómo Extraer Todas Las Direcciones de Email de Cadenas o Archivos TXT

También puede leer artículos de web scraping en el sitio web oficial


Author: The Octoparse Team 

Octoparse Download


More Resources


RegEx: How to Extract All Email Addresses from TXT Files or Strings

How to Generate Sales Lead Using Web Scraping?

Email Extractor: Gathering Sales Leads in Minutes

Top 20 Web Scraping Tools to Scrape the Websites Quickly

Web Scraping Templates Take Away


Laden Sie Octoparse herunter, um mit Web-Scraping zu beginnen, oder kontaktieren Sie uns
für die Fragen über Web Scraping!

Kontaktieren Sie uns Herunterladen
Diese Website verwendet Cookies um Ihnen ein besseres Internet-Erlebnis zu ermöglichen. Lesen Sie wie wir Cookies verwenden und Sie können sie kontrollieren, indem Sie auf Cookie-Einstellungen klicken. Wenn Sie die Website weiter nutzen, akzeptieren Sie unsere Verwendung von Cookies.
Akzeptieren Ablehnen