^start of line
Comment: begin
\s*any whitespace character, repeated any number of times
Comment: some empty spaces
Non-Capturing Group(?:
\+? # + symbol
\d{1,2} # country code
\s*
(?(?=\)) # if followed by parens
| # then dash not allowed
-? # else optional dash
)
)? ?repeats the group contents below at most once:
\+?optionally matches the literal + (4310 / 538 / 2B16)
Comment: + symbol
\d{1,2}a digit, repeated between 1 and 2 times
Comment: country code
\s*any whitespace character, repeated any number of times
Condition(?(?=\)) # if followed by parens
| # then dash not allowed
-? # else optional dash
) Uses the first branch if the lookaround matches
\)the literal ) (4110 / 518 / 2916)
If the condition is true, match this branch: # if followed by parens
Comment: if followed by parens
Otherwise, match this branch: # then dash not allowed
-? # else optional dash
Comment: then dash not allowed
-?optionally matches the literal - (4510 / 558 / 2D16)
Comment: else optional dash
Comment: prefix like +380
\s*any whitespace character, repeated any number of times
Non-Capturing Group(?:
(?P<leftparen>\()? # optional left paren
\s*
0\d\d
\s*
(?(leftparen)\)|) # right paren if and only if left paren
)? ?repeats the group contents below at most once:
Group leftparen(?P<leftparen>\()? ?repeats the group contents below at most once:
\(the literal ( (4010 / 508 / 2816)
Comment: optional left paren
\s*any whitespace character, repeated any number of times
0the literal text 0
\da digit
\da digit
\s*any whitespace character, repeated any number of times
Condition(?(leftparen)\)|) Uses the first branch if group leftparen matched
If the condition is true, match this branch:\) \)the literal ) (4110 / 518 / 2916)
Otherwise, match this branch: — matches an empty string
Comment: right paren if and only if left paren
Comment: operator code, starting with 0, optinally in parentheses
Condition(?(?<=\)) # if preceded by parens
\s*| # then dash not allowed
\s*-?\s* # else optional dash
) Uses the first branch if the lookaround matches
Positive Lookbehind(?<=\)) \)the literal ) (4110 / 518 / 2916)
If the condition is true, match this branch: # if preceded by parens
\s* Comment: if preceded by parens
\s*any whitespace character, repeated any number of times
Otherwise, match this branch: # then dash not allowed
\s*-?\s* # else optional dash
Comment: then dash not allowed
\s*any whitespace character, repeated any number of times
-?optionally matches the literal - (4510 / 558 / 2D16)
\s*any whitespace character, repeated any number of times
Comment: else optional dash
Non-Capturing Group(?:
\d |
(?<=
\d
)
(?(sep)
(?P=sep)|
(?P<sep>[\-\/\ ])
)
(?=
\d
)
){5,13} {5,13}repeats the group contents below between 5 and 13 times:
2nd Alternative
(?<=
\d
)
(?(sep)
(?P=sep)|
(?P<sep>[\-\/\ ])
)
(?=
\d
)
Positive Lookbehind(?<=
\d
) Condition(?(sep)
(?P=sep)|
(?P<sep>[\-\/\ ])
) Uses the first branch if group sep matched
If the condition is true, match this branch:
(?P=sep) (?P=sep)the text saved by group sep
Otherwise, match this branch:
(?P<sep>[\-\/\ ])
Group sep(?P<sep>[\-\/\ ]) \-the literal - (4510 / 558 / 2D16)
\/the literal / (4710 / 578 / 2F16)
\ the literal (3210 / 408 / 2016)
Positive Lookahead(?=
\d
) \s*any whitespace character, repeated any number of times
Comment: some empty spaces
$end of line
Comment: end
Comment: \d\d\d (?P<separator>-?) \d\d (?P=separator) \d\d $
m modifier: multiline. Causes ^ and $ to match the start and end of each line, not only the start and end of the string
g modifier: global. Finds all matches instead of stopping after the first
x modifier: extended. Ignores unescaped whitespace and comments outside character classes