Autoreplacement for phone numbers
There are many possible ways to write the same phone number. 81234567890
, +71234567890
, 1234567890
and 8 (123) 4567890
are only a few obvious formatting examples. If you are getting calls from multiple countries, the number of options may be very high.
For a human, those options are not very different. All of them will work if you dial them on the phone; it's easy to compare them and understand that they are the same number. However, for software, they are completely different numbers. For example, if you have a contact saved in CRM with a number starting with +7, but you type the same number in the search with 8 instead, then the search may not show this contact.
We used to only have number formatting in customizations to solve this problem. Now we've added an autoreplacement function in Itgrix bx v3.7.0 and Itgrix amo v2.10.0. It allows to configure number formatting using regular expressions (regexp) right from the admin panel.
Autoreplacement modifies client and/or user phone numbers that match templates by replacing whole numbers or their parts with substitutions. Multiple replacement patterns can be configured simultaneously.
Replacements are executed before requests are sent to CRM, so autoreplacement affects the creation and search of entities, tasks, and users.
All replacements are executed for each number one by one in turns. It means that the order of replacements is important, as the execution of the first replacement may make the number match or not match the following templates.
Regular expressions
We use the language of regular expressions (regexp) to describe the rules of autoreplacement, the same as we used to do before in customizations. This is a commonly used way of matching and modifying text.
To create and test regular expressions, we suggest using online tools, such as regex101.com (choose Golang in the left menu and lower choose Substitution to test replacements).
Shortlist of useful pattern elements
Symbols
^
 beginning of a line$
 end of a line.
 any symbol\d
 a digit\D
 not a digit\w
 a digit or a letter\W
 not a digit and not a letter\s
 space (including unusual varieties, such as nolinebreak spaces)\S
 not a space[ab\s05]
 either:a
,b
, space or digit between0
and5
abc 123
 literally "abc 123", possibly as a part of bigger text fragmentabc123
 either "abc" or "123", possibly as a part of bigger text fragment^abc 123$
 "abc 123" as a whole line without additional text before or after\(
,\)
,\[
,\]
,\{
,\}
,\+
,\?
,\*
,\.
,\
,\\
 literal representation of symbols that have special meaninng when not preceeded by\
Repetitions
You can specify how many times a symbol or a group can be repeated by adding of the the following immediately after.
?
 0 or 1 time+
 1 or more times*
 any number of times (even zero){5}
 5 times{5,10}
 5 to 10 times{,10}
 0 to 10 times{5,}
 5 or more times
For example, \d{10}
means "ten digits", \+?
means "plus sign, zero or one time" and 0+
means "one or more zeroes".
Groups and substitutions
Symbols can be combined into groups using brackets. This is useful for repeating multiple symbols. For example, (10){3}
means "101010".
Text from groups can be used in substitutions as $N
where N
is the number of a group.
For example, when using a pattern 8(\d{6})(\d{4})
, the substitution $1
would mean the contents of the group (\d{6})
 the first 6 digits after "8". The substitution $2
would mean the contents of the group (\d{4})
 the following 4 digits.
Examples of autoreplacement for client numbers
Pattern  Substitution  Description 


 Replaces prefixes 

 Replaces 

 Replaces a number with 10 in the end with 

 Adds a prefix 
 (empty string)  Removes all symbold except digits, e.g. 
 (empty string)  Removes all spaces, brackets and dashes, e.g. 

 Formats a number as 

 Replaces a number composed of "zero, two digits, more digits" with 

 Replaces 

 Replaces a literal number 
Examples of autoreplacement for user numbers
Pattern  Substitution  Description 


 Removes everything except the last 4 digits, e.g. 

 Removes a prefix 

 Removes everything except the last 4 digits from a number ending with 

 Replaces the first digit 

 Replaces literal number 
Last updated