Regex Split on forward slash?

Phil Mayers p.mayers at
Tue Dec 17 12:46:52 CET 2013

On 17/12/13 03:18, Peter Lambrechtsen wrote:

> Essentially I am trying to do a split on the ADSL Circuit ID:
> ADSL-Agent-Circuit-Id = "POLT01 eth 1/1/02/05/4/14/1:10"
> And trying to grab the value in the 6th split being "14" and check it's
> a 14.
> I would have hoped something like this regex would work:
>  /(?<=\/)([\w-]*)(?=\/)/

Few things:

  1. This looks like a PCRE regexp; are you sure you're compiling w/ 
PCRE support?

  2. The "\w" will need double-backslash i.e. \\w - the double-slash 
makes the unlang parser emit a single slash to the regexp input. The 
regexp parser in unlang is a bit funky in this regard I'm afraid :o(

  3. However you should only need to single-escape the regexp deliminter 
(i.e. once, for the unlang parser).

  4. That regexp doesn't work for me when I try it from the python repl; 
how are you sure it's right

  5. It's obvious from your text that you're assuming the regexps work 
differently than they do - they don't do a "searchall" operation or 
similar. It's a single match, and each %{n} refers to a single capture 
group from a single match.

You'll need to write out a regexp in full that matches your input e.g.

if (blah =~ /\\w+ \\w+ .+\/.+\/.+\/.+\/.+\/(.+)\/.+/) {
   update control {
     Tmp-String-0 := "6th /-delimited is %{1}"

More information about the Freeradius-Users mailing list