Every time a regular expression is evaluated, whether it matches or not,
the numbered capture group values will be cleared.
-=== +%regex(<named capture group>}+
+=== +%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(<named capture
+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 xref:xlat/builtin.adoc#_0_32[above].
if ("foo" =~ /^(?<name>.*)/) {
noop
}
-%regex(name) == "foo"
+%regex.match(name) == "foo"
@endverbatim
*
* @ingroup xlat_functions
XLAT_NEW("hash.md4");
#if defined(HAVE_REGEX_PCRE) || defined(HAVE_REGEX_PCRE2)
+ if (unlikely((xlat = xlat_func_register(xlat_ctx, "regex.match", xlat_func_regex, FR_TYPE_STRING)) == NULL)) return -1;
+ xlat_func_args_set(xlat, xlat_func_regex_args);
+ xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_INTERNAL);
if (unlikely((xlat = xlat_func_register(xlat_ctx, "regex", xlat_func_regex, FR_TYPE_STRING)) == NULL)) return -1;
xlat_func_args_set(xlat, xlat_func_regex_args);
xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_INTERNAL);
+ XLAT_NEW("regex.match");
#endif
{
}
# Check failure when no previous capture - full capture
-if (%regex()) {
+if (%regex.match()) {
test_fail
}
request -= Module-Failure-Message[*]
# Check failure when no previous capture - named group
-if (%regex('foo')) {
+if (%regex.match('foo')) {
test_fail
}
request -= Module-Failure-Message[*]
# Check failure when no previous capture - numbered group
-if (%regex(Port-Limit)) {
+if (%regex.match(Port-Limit)) {
test_fail
}
# uncompiled - ref - named capture groups
if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])%{dummy_string}/) {
- result_string := "%regex('seven')_%regex('six')_%regex('five')_%regex('four')_%regex('three')_%regex('two')_%regex('one')_%{0}"
+ result_string := "%regex.match('seven')_%regex.match('six')_%regex.match('five')_%regex.match('four')_%regex.match('three')_%regex.match('two')_%regex.match('one')_%{0}"
if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
test_fail
}
# Checking capture groups are cleared out correctly
if (User-Name =~ /^(?<one>[0-9])_%{dummy_string}/) {
- result_string := "%{0}%regex('one')%regex('two')%regex('three')%regex('four')%regex('five')%regex('six')%regex('seven')"
+ result_string := "%{0}%regex.match('one')%regex.match('two')%regex.match('three')%regex.match('four')%regex.match('five')%regex.match('six')%regex.match('seven')"
if (!(result_string == '1_1')) {
test_fail
}
# Checking capture groups are cleared out correctly when there are no matches
if (User-Name =~ /^.%{dummy_string}/) {
- result_string := "%{0}%regex('one')%regex('two')%regex('three')%regex('four')%regex('five')%regex('six')%regex('seven')"
+ result_string := "%{0}%regex.match('one')%regex.match('two')%regex.match('three')%regex.match('four')%regex.match('five')%regex.match('six')%regex.match('seven')"
if (!(result_string == '1')) {
test_fail
}
# compiled - ref - named capture groups
if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])/) {
- result_string := "%regex('seven')_%regex('six')_%regex('five')_%regex('four')_%regex('three')_%regex('two')_%regex('one')_%{0}"
+ result_string := "%regex.match('seven')_%regex.match('six')_%regex.match('five')_%regex.match('four')_%regex.match('three')_%regex.match('two')_%regex.match('one')_%{0}"
if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
test_fail
}
# compiled - xlat - named capture groups
if ('1_2_3_4_5_6_7' =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])/) {
- result_string := "%regex('seven')_%regex('six')_%regex('five')_%regex('four')_%regex('three')_%regex('two')_%regex('one')_%{0}"
+ result_string := "%regex.match('seven')_%regex.match('six')_%regex.match('five')_%regex.match('four')_%regex.match('three')_%regex.match('two')_%regex.match('one')_%{0}"
if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
test_fail
}
g := 6
h := 7
- result_string := "%regex(h)_%regex(g)_%regex(f)_%regex(e)_%regex(d)_%regex(c)_%regex(b)_%regex(a)"
+ result_string := "%regex.match(h)_%regex.match(g)_%regex.match(f)_%regex.match(e)_%regex.match(d)_%regex.match(c)_%regex.match(b)_%regex.match(a)"
if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
test_fail
}