Regular expression (regex) reference

Regular expressions can be used in conjunction with Pexip Infinity features including Call Routing Rules, Provisioning VMRs, devices and users from Active Directory via LDAP and searching the support and admin logs.

This topic contains information on:

Regex testing tool

The Pexip Infinity Administrator interface contains an inbuilt regex testing tool:

  1. Go to Utilities > Regular Expression Tester.
  2. Enter your test input and regex:

    Option Description
    Input The test input to match against the regular expression, such as a dialed alias.
    Regex match The regular expression that the Input is checked against (see Regex syntax below).
    Regex replace string The optional regular expression string used to transform the Input (if a match was found). Leave this field blank to leave the original input unchanged.
  3. Select Test Regular Expression (at the bottom of the page).

    The Result field shows the result of transforming the Input using the Regex match and Regex replace string. If a Regex replace string was not provided then the Result will be the same as the Input, providing it was a full match.

    The Debug information shows extra information such as whether it was a successful, partial or failed match, and lists any match groups.

Regex syntax

BRE (basic regular expression) syntax is used when searching the support and admin logs.

Otherwise (call routing and provisioning), Pexip Infinity supports case-insensitive Perl-style regular expression patterns as described in the rest of this topic. The table below describes some of the special characters that are commonly used in regular expressions, and provides examples of how they can be used.

Character Description Example
Basic syntax
non-special character Matches the specified characters literally (providing they are not any of the regex special characters). abc matches abc, ABC, aBC etc
(...) Groups a set of matching characters together. Multiple groups can be specified. Each group can then be referenced in order (from left to right) using the characters \1, \2, etc. as part of a replace string. See Search and replace examples below
\

Escapes a regular expression special character: {}[]()^ $.|*+?\

Also used to reference a group in a replace expression.

ab\+ matches ab+
| Matches either one expression or an alternative expression. .*@example\.(net|com) matches against any URI for the domain example.com or the domain example.net
Wildcard and character matching
. Matches any single character. a.c matches aac, abc, azc, a2c, a$c etc.
\d Matches a decimal digit character (i.e. 0-9). a\d matches a1, a2, a3 etc. but not aa, ab etc
\D Matches a non-digit character. a\D matches ab but not a1, a2, a3 etc
\s Matches any whitespace character (space, tab, newline). ab\sd matches ab d but not abcd, abxd etc
\S Matches any non-whitespace character. ab\Sd matches abcd, abxd etc. but not ab d
[...]

Matches the characters specified in the brackets.

You can specify a range of characters by specifying the first and last characters in the range, separated by a hyphen.

You cannot use other special characters within the [] — they will be taken literally.

9[aeiou] matches 9a, 9e, 9i etc. and 9A, 9E, 9I etc, but not 9b, 9c, 9B, 9C etc

9[a-z] matches 9a, 9b, 9z etc. and 9A, 9B, 9Z etc. but not strings such as 91, 99 or 9(

[0-9#*] matches any single E.164 character (digits 0-9, hash key or asterisk)

[^...] Matches anything except the set of specified characters.

[^a-z] matches any non-alphabetical character

[^0-9#*] matches anything other than an E.164 character

Repetition factors
* Matches 0 or more repetitions of the previous character or expression. ab*c matches ac, abc, abbc, but not ab or abd
+ Matches 1 or more repetitions of the previous character or expression.

ab+c matches abc and abbc, but not ab, ac or abd

[a-z.]+ matches any string containing the letters a to z, A to Z, or dots (periods)

? Matches 0 or 1 repetitions of the previous character or expression. ab?c matches ac and abc, but not ab, abbc or abd
.* Matches against any sequence of characters. a.* matches everything beginning with a
{n} Matches n repetitions of the previous character or expression.

ab{2}c matches abbc, but not abc or abbbc

a\d{3} matches a123and a789, but not a12 or 456

{n,m} Matches n to m repetitions of the previous character or expression. ab{2,4}c matches abbc, abbbc and abbbbc, but not abc or abbbbbc
{n,} Matches at least n repetitions of the previous character or expression. ab{2,}c matches abbc, abbbc, abbbbc etc, but not abc
Position matching
^ Matches the beginning of a line. ^meet\.(.*) matches any string that starts with meet. and places the rest of the string into a group (which could be used in a replace string).
$ Matches the end of the line. .*\.com$ matches any string that ends in .com
(?!...) Negative lookahead. Defines a subexpression that must not be present immediately after the current match position, for example regex1(?!regex2) where a match is found if regex1 matches and regex2 does not match.

(?!.*@example\.com$).* matches any string that does not end with @example.com

(?!meet).* matches any string that does not start with meet

meet(?!\.).* matches any string that starts with meet providing it is not followed by a period

(?<!...) Negative lookbehind. Defines a subexpression that must not be present immediately before the current match position, for example (?<!regex1)regex2 where a match is found if regex1 does not match and regex2 matches. .*(?<!@)example\.com.* matches any string containing example.com providing it is not preceded by @

Note that this is only a subset of the full range of expressions. For a full description of regular expression syntax see http://perldoc.perl.org/perlre.html.

Pattern matching examples

VMR naming patterns

If your videoconferencing rooms have an alias naming convention in the form oslo1@example.com, oslo2@example.com, newyork1@example.com etc, this could be matched with an expression such as:

[a-z]+\d@example\.com

Or, if the rooms are named 555 followed by exactly three digits, e.g. 555100@example.com and 555234@example.com, you could use the expression:

555\d{3}@example\.com

If your room aliases could follow either pattern, you could merge the two expressions like this:

([a-z]+\d|555\d{3})@example\.com

Matching an IP address

To match against an IP address, use:

^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$

To match against somebody dialing an IP address (e.g. from an H.323 device or the web app), or someone dialing a SIP URI in the format IP_address@example.com, use a Destination alias regex match of:

^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))(@example\.com)?$

with a Destination alias regex replace string of: \1

and this combination of settings will ignore any @example.com element and pass just the IP address.

Search and replace examples

Replacing an alias domain

This example transforms any alias that ends in example.net into an alias that ends in example.com:

Match string: (.+)(@example\.net$)
Replace string: \1@example.com

This example builds on the previous example by transforming any alias that ends in example.com, example.net or example.co.uk into a common alias that ends in example.com:

Match string: (.+)(@example\.(com|net|co\.uk)$)
Replace string: \1@example.com

Strip leading 9

This example strips a leading 9 from any all-numeric (0-9) alias (e.g. for integrating with an ITSP phone gateway service):

Match string: 9([0-9]+$)
Replace string: \1

If your environment includes a PSTN gateway or uses an ITSP (Internet telephony service provider), consider the potential for toll fraud if you have Call Routing Rules that can route calls to the PSTN gateway or ITSP, or if you allow conference participants to dial out to other participants via the PSTN gateway or ITSP. See PSTN gateways and toll fraud for more information.