Regex question

Phil Mayers p.mayers at imperial.ac.uk
Thu Oct 24 17:18:24 CEST 2013


On 24/10/2013 12:54, Franks Andy (RLZ) IT Systems Engineer wrote:
> Hi, thanks for the reply.
>
> My original regex was
>
> /^email:([a-z0-9_-]+(\\.[a-z0-9_-]+)*@[a-z0-9_-]+(\\.[a-z0-9_-]+)*(\\.[a-z]{2,4}))/
> <mailto:*@[a-z0-9_-]+(\\.%5ba-z0-9_-%5d+)*(\\.%5ba-z%5d%7b2,4%7d))/>
>
> You’re correct with the escaping thing, I was just quickly trying a
> shorter simpler version. I didn’t know you needed to escape characters
> inside a match [] though.
>
> Anyway, online testers are working fine, just FR or the internal regex
> library that isn’t. I tried compiling with and without libpcre3-dev and
> no change.

If you're matching "-" in a "[]", it should be the first char, else it 
signifies a range. Like this:

[-_.A-Za-z0-9]

You shouldn't need to escape "-_." in "[]" in FR regexps; just put "-" 
first.

Secondly, remember that anything you want to escape in a regexp will 
need double-backslash, as FR parser obeys \x even inside regexp //.

We use a regexp like this:

if (Realm =~ /^([-A-Z0-9]+(\\.[-A-Z0-9]+)+)$/)

Notice the lack of backslash for "-" at the start of the range, and the 
double-backslashed "." to match a literal dot.


More information about the Freeradius-Users mailing list