[nsp] regexp question

David Flynn davidf at woaf.net
Tue Apr 6 11:12:23 EDT 2004


* rasmus (posts) (lom at doruk.net.tr) wrote:
> This should work fine,
> ^(1234_)+([0-9]+_)+$

Unfortunately not, it falls into the trap that is too simple to make:

([0-9]+_)+ fails to do what you want for precisely the same reason that
[0-9]+ does what you want.

The regex is nothing more than a pattern, conceptually (almost) the
following are the same:

     ([0-9]+_)+
and  ([0-9]+_)([0-9]+_)([0-9]+_)

if matching "123 456 789"

All the + means is to repeat the last pattern, not match whatever caused
the previous pattern to succeed.  The parenthesis only serve to create
a subexpression which an operator can play with ('+' in the above case).

The exact same thing is happening with [0-9]+, it conceptually the same
as [0-9][0-9][0-9] when matching a three byte number.


> ([0-9]+_)+$  # this accepts any ASNs with any prependings also,

Yes this is right in the use of the word `any', but it is a list of any asn,
infact that on its own will match the whole table.

> ^(1234_)+([0-9]+_)+$

ie, that is the same as ^1234_

(the rest of it is redundant by definition)

..david


More information about the cisco-nsp mailing list