FreeRADIUS InkBridge

Regular Expression Expansions

%regex.search(pattern, string)

Performs a regular expression search on string, using pattern. If there are subgroups in pattern, the subgroups are available via a subsequent %regex.match(). Each regular expression search (or =~ operator) clears and refreshes the list of matches in %regex.match().

This function is the same as using %{string =~ /pattern/}. However, this function is included for completeness.

%regex.match(0)..%regex.match(32)

%regex.match(0) expands to the portion of the subject that matched the last regular expression evaluated. %regex.match(1)..%regex.match(32) expand to the contents of any capture groups in the pattern.

Every time a regular expression is evaluated, whether it matches or not, the numbered capture group values will be cleared.

%regex.match(<named capture group>}

Return named subcapture value from the last regular expression evaluated.

Results of named capture groups are available using the %regex.match(<named capture group>} expansion. They will also be accessible using the numbered expansions described above.

Every time a regular expression is evaluated, whether it matches or not, the named capture group values will be cleared.

This expansion is only available if the server is built with libpcre2. Use the output of radiusd -Xxv to determine which regular expression library in use.

...
Debug :   regex-pcre2              : yes
Debug :   regex-posix              : no
Debug :   regex-posix-extended     : no
Debug :   regex-binsafe            : yes
...
Debug :   pcre2                    : 10.33 (2019-04-16) - retrieved at build time
Example 1. Using a numbered subpattern after a search
if (%regex.search("(j)(i(m))", User-Name)) {
    reply.Reply-Message := %regex.match(2)
}
Output when User-Name == "jim"
im
Example 2. Using a named subpattern after a search
if (%regex.search("(?<first>b.*)b", User-Name)) {
    reply.Reply-Message := %regex.match("first")
}
Output when User-Name == "bob"
bo