How does it work?

This criteria lets you match based on a regular expression against a string. You can use it to flexibly apply behaviors depending on the contents of dynamic variables.

Fields

In the Match String field, enter a string – typically a dynamic variable, such as a built-in variable like AK_HOST or a user-defined PMUSER variable.

In the Regex field, enter a Perl Compatible Regular Expression (PCRE) to match against the string. Note that while you can specify grouping subexpressions using parentheses, you cannot extract variables from the Match String.

Also, specify if the regular expression match should be case-insensitive – this applies to the entire Regex string match. See the second example below for more information.

Examples

  1. Match the incoming hostname (stored in the AK_HOST variable) against a set of allowed hosts, all of which contain any of test or qa or dev either preceded or followed by a dash (or both) somewhere in the hostname:

    Match String: {{builtin.AK_HOST}}
    Regex: ^(.*)?(-(test|qa|dev))|((test|qa|dev)-)(.*)?\.com$

    In this example, it would match against any of the following hostnames (assuming that they are defined in the configuration):

    • qa-example.com
    • example-test.com
    • example-dev-7.com

    But it would not match against any of the following hostnames:

    • exampledev7.com – no dash preceding/following dev
    • example-test.org.org rather than .com
  2. Match the request path (stored in the AK_PATH variable) to ensure that it has a format of an “apps” path segment followed by a path segment consisting of a letter (upper or lower case) followed by 3 to 5 digits, and then a “user” path segment optionally followed by further path segments:

    Match String: {{builtin.AK_PATH}}
    Regex: ^\/apps\/(?:[a-zA-Z][0-9]{3,5})\/user(?:\/.*)?$

    In this example, it would match against any of the following paths:

    • /apps/a123/user
    • /apps/Z98765/user/coolstuff/abc
    • /apps/b8888/user/

    But it would not match against the following paths:

    • /apps/a12/user – only two digits in the 2nd path segment
    • /apps/98765/user/coolstuff/abc – no leading letter in the 2nd path segment
    • /apps/b8888/usersusers rather than user

    If you want to allow any upper- or lower-case characters in the above paths (e.g. you want to allow /APPS/a1234/User), you could specify Case Sensitive as Off.

References

A useful Regular Expression reference and test site is Regex101 PCRE.
Note that this is not an ​Akamai​ site.

❗️

External sites

Please note, any external link(s) to other site(s) outside of the ​Akamai​.com domain, are being provided only for convenience and informational purposes; and ​Akamai​ bears no responsibility for the accuracy, legality or content of such external site(s) or such external link(s).

Usage Notes

Regular expression matches are relatively "expensive" in terms of CPU usage and should be avoided unless there is realistically no other way to perform the same match. For instance, the first example above could probably be replaced with a Hostname match, unless the configuration includes hundreds of possibly-matching hostnames.

If a Regex match is used together with any other matches in the same rule as Match All, the other matches should be specified first, to avoid the "expensive" Regex match being invoked if any of the other matches do not evaluate to true.