Regex match on a variable is not working if length is long

Alan DeKok aland at deployingradius.com
Wed Dec 11 14:48:14 CET 2019


On Dec 11, 2019, at 4:06 AM, Chinnapaiyan, Nagamani <Nagamani.Chinnapaiyan at viasat.com> wrote:
> This one works,
> 
> (6)        if ( "%{control:Tmp-String-7}" =~ /vendor-options.*\(number 43\)\(value (([0-9a-fA-F]{2}:)*[0-9a-fA-F]{2})/ ) {

  One possibility is to fix the expression.  You're not using the capture groups, so there's no need to the regex engine to store them.

  You should be able to use:

	 if (&control:Tmp-String-7 =~ /vendor-options.*\(number 43\)\(value (?:(?:[0-9a-fA-F]{2}:)*[0-9a-fA-F]{2})/ ) {

  Which tells PCRE to not store the capture groups.

  But it's also not clear why you're doing *parsing* either.  If the vendor options are *always* hex, then you don't need to check that.  Just change the regular expression so:

	if ( &control:Tmp-String-7 =~ /vendor-options.*\(number 43\)\(value (.*)/ ) {

  On the other hand, if you need to parse the "00:00:00" strings and covert them to hex, then it's probably best to avoid regular expressions.  They're just not designed for that.

  Alan DeKok.




More information about the Freeradius-Users mailing list