Extract Phone Number

Extracts phone numbers from the specified text.

Command availability: IBM RPA SaaS and IBM RPA on premises


Extracts phone numbers from the specified text according to the Language and the Default Area Code.

The results that this command returns might vary according to the selected NLP provider. For more information, see Setting an NLP provider.

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

extractPhoneNumber --defaultareacode(String) [--culture(String)] --text(String) (List<PhoneNumber>)=values (PhoneNumber)=first (DataTable)=valuesmapping (Boolean)=success

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Default Area Code defaultareacode Required Text The default area code of the phone numbers present in the input text.

Important:The default area code is 00 for countries other than Brazil and the United States of America.
Language culture Optional Text, Culture Language used to extract the phone number.

If you define the language manually, make sure to enter only supported language codes. See the culture parameter options for supported languages.

Important:The number formatting changes according to the defined language.
Text text Required Text Input text containing the phone numbers to be extracted.

Important:Phone number values entered in the Text parameter must be properly formatted according to the Language defined.

culture parameter options

The following table displays the options available for the culture input parameter. The table shows the options available when working in Script mode and the equivalent label in the Designer mode.

Designer mode label Script mode name Description Supported provider
ar ar Arabic Watson NLP
zh-CN zh-CN Chinese (Simplified) Watson NLP
zh-TW zh-TW Chinese (Traditional) Watson NLP
cs cs Czech Watson NLP
da da Danish Watson NLP
nl nl Dutch Watson NLP
de-DE de-DE German Watson NLP
en-US en-US English Legacy and Watson NLP
fi fi Finnish Watson NLP
fr-FR fr-FR French (France) Watson NLP
fr-CA fr-CA French (Canada) Watson NLP
he he Hebrew Watson NLP
it-IT it-IT Italian Watson NLP
ja-JP ja-JP Japanese Watson NLP
ko-KR ko-KR Korean Watson NLP
nb nb Norwegian Bokmal Watson NLP
nn nn Norwegian Nynorsk Watson NLP
pt-BR pt-BR Portuguese (Brazil) Legacy and Watson NLP
pt-PT pt-PT Portuguese (Portugal) Legacy and Watson NLP
pl pl Polish Watson NLP
ro ro Romanian Watson NLP
ru-RU ru-RU Russian Watson NLP
sk sk Slovak Watson NLP
es-ES es-ES Spanish Watson NLP
sv sv Swedish Watson NLP
tr tr Turkish Watson NLP

Output parameters

Designer mode label Script mode name Accepted variable types Description
Values values List<Phone Number> List of phone numbers extracted from the text.
First value first Phone Number First phone number extracted from the text.
Values mapping valuesmapping Data Table Data table with extracted values mapped by rows and columns.

See the valuesmapping parameter options section for details.
Success success Boolean Returns True if the extraction succeeds, or False otherwise.

valuesmapping parameter options

This parameter returns a data table that contains the occurrence of each phone number value that is extracted from the input text.

The following list shows the mapped values:

  • The index value in the list of extracted phone numbers. Index values start at 1.
  • Position in number of characters where the value was found in the text.
  • Length of the extracted value.
  • Text from which the phone number was extracted.
  • Phone numbers extracted.


The following example demonstrates the use of the Extract phone number command using English as the language and 408 as the area code.

defVar --name listNumbersPhones --type List --innertype PhoneNumber
defVar --name firstPhoneNumberFound --type PhoneNumber
defVar --name result --type Boolean
extractPhoneNumber --defaultareacode 408 --culture en-US --text "Phone number: \r\n+1 408 555-4874\r\n+1 409 556-1754\r\n+1 410 745-1244" listNumbersPhones=values firstPhoneNumberFound=first result=success
logMessage --message "Phone Number List: ${listNumbersPhones}\r\nFirst Phone Number: ${firstPhoneNumberFound}\r\nResult: ${result}" --type "Info"
// Phone Number List: [+1 (40) 555-4874,+1 (40) 556-1754,+1 (41) 745-1244]
// First Phone Number: +1 (40) 555-4874
// Result: True