81234567890
, +71234567890
, 1234567890
and 8 (123) 456-78-90
are only a few obvious formatting examples for Russian numbers. And if you're getting calls from multiple countries, the number of options is very high.
For a human, those options are not so different. All of them will work if you dial them; it's easy to compare them to 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 enter the number in the search with 8, then the search may not show this contact.^
- 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 no-line-break spaces)\S
- not a space[ab\s0-5]
- either: a
, b
, space or digit between 0
and 5
abc 123
- literally "abc 123", possibly as a part of bigger text fragmentabc|123
- 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 \
?
- 0 or 1 time+
- 1 or more times*
- any number of times{5}
- 5 times{5,10}
- 5 to 10 times{,10}
- 0 to 10 times{5,}
- 5 or more times\d{10}
means "ten digits", \+?
means "zero or one plus sign" and 0+
means "one or more zeroes".(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.^\+?7(\d{10})$
8$1
+7
and 7
in the beginning of a number that consists of a prefix followed by 10 digits with 8
, e.g. +74951234567
→ 84951234567
and 74951234567
→ 84951234567
This pattern is enabled by default^\+7
8
+7
in the beginning of any number with 8
, e.g. +712345671234567
→ 812345671234567
.*(\d{10})$
8$1
8
and those 10 digits, e.g. 0071234567890
→ 81234567890
^(\d{7})$
8495$1
8495
to a 7-digit number, e.g. 1234567
→ 84951234567
\D
+7 (495) 123-45-67
→ 74951234567
[\s()-]
+7 (495) 123-45-67
→ +74951234567
^(.*)(\d{3})(\d{3})(\d{2})(\d{2})$
$1 ($2) $3-$4-$5
x (xxx) xxx-xx-xx
, e.g. +74951234567
→ +7 (495) 123-45-67
^0\d{2}(\d+)$
8$1
8
and the digits from the end of a number, e.g. 0771234567890123
→ 81234567890123
1234567$
7654321
1234567
in the end of a number with 7654321
, e.g. 84951234567
→ 84957654321
^84951234567$
84957654321
84951234567
with 84957654321
.*(\d{4}$)
$1
+71234564321
→ 4321
^8123456(\d{4})$
$1
8123456
, leaving last 4 digits, e.g. 849576543214321
→ 4321
.*123456(\d{4})$
$1
123456
and 4 more digits, e.g. +71234564321
→ 4321
^1\d{3}$
2$1
1
of a 4-digit number with 2
, e.g. 1234
→ 2234
^1234$
4321
1234
with 4321