RE: regular express question

From: Tim Fletcher (tim@fletchmail.net)
Date: Fri Apr 18 2003 - 12:33:55 GMT-3


Greedy means a subexpression will match as many times as possible, while
still allowing the rest of the string to match.

For example, lets look at the following string: "10 20 30 40"

Now lets apply the following RE: "10_(.*)0.*"
(the parenthesis and the trailing ".*" serve no purpose other than
illustration here)

You might expect it to match as "10 (2)0 30 40", but it would really match
as follows "10 (20 30 4)0". That's because the ".*" will continue to match
as long as the rest of the expression is satisfied.

So let's go back to the original RE.
_2400_(.+_)*3500_

I think everyone understands everything up to the 1st parenthesis, so let's
start with what's inside the parenthesis. ".+_" means match any charter, 1
or more times followed by a space (or end of string, but that is not
applicable here). This entire expression can then occur either 0 or more
times, followed by "3500_". So if we apply this to our AS path:
2400 10 20 3500

It matches as follows:
_ matches the beginning if the string
2400 matches literally
_ matches the space between 2400 and 10
.+ matches "10 20"
_ matches the space between 20 and 3500
3500 matches literally
_ matches the end of the string

So ".+" matches "10 20" because it can (remember that "." matches any
charter, including space), and still match the rest of the expression. The
result of this is that the subexpression "(.+)" will only ever match 0 or 1
times, so we can use either ? or * after it with the same results.

Also, because the only time the subexpression within the parenthesis will
match anything, is when there is 1 or more AS numbers between the 2400 and
3500, the "." will always match one or more characters, so we can use
either + or * after that. Hence the 3 REs I listed below, as well as 1 I
forgot, are all equivalent.

-Tim Fletcher #11406

At 10:06 PM 4/17/2003 -0400, OhioHondo wrote:
>Tim
>
>I really want to understand this but I do not understand how the "space"
>fits in. By your explanation it 'stops the greediness' of the expression and
>allows the 3550 to be recognized as a unique AS ---
>
>I guess I don't understand this stop mechanism and why the 3550 is not
>gobbled up by the "greedy" part of the expression.
>
>Could you offer an indepth explanation for my benefit???
>
>-----Original Message-----
>From: nobody@groupstudy.com [mailto:nobody@groupstudy.com]On Behalf Of
>Tim Fletcher
>Sent: Thursday, April 17, 2003 8:46 PM
>To: Garnet Ulrich; ccielab
>Subject: RE: regular express question
>
>
>Garnet,
>
>Your as-path list will work just fine, as will the one you mentioned from
>the previous e-mail. They will both meet the requirement. Consider the
>following regular expression and AS path:
>
>RE: _2400_(.+_)*3500_
>AS: 2400 10 20 3500
>
>The 1st underscore matches the beginning of the string, followed by a
>literal 2400, and the 2nd underscore matches the space between 2400 and 10.
>Now you might think that the ".+_" would match "10 " for 1 match, then "20 "
>for a 2nd match, but it really matches "10 20 " in a single match. The
>reason is that regular expressions are "greedy", meaning they will match as
>many charters as they can. So in this case, it will match everything up to a
>space followed by the literal 3500. So in reality, any of the following will
>work the same.
>
>_2400_(.*_)*3500_
>_2400_(.+_)*3500_
>_2400_(.*_)?3500_
>
>You just have to make sure you allow for any length string in the middle,
>followed by a space, and that the middle section is optional.
>
>-Tim Fletcher
>
>At 05:52 PM 4/16/03 -0400, Garnet Ulrich wrote:
> >I just tested this stuff and what I found is that even if you enter
> >separate
> >
> >match as-path x
> >match as-path y
> >
> >statements in your route-map, they get automatically converted to a
> >single "match as-path x y" statement which means logical OR. I
> >confirmed that it takes it as an OR.
> >
> >The best way I could come up with to match on routes with both ASes in
> >the path was the following as-path access-list:
> >
> >ip as-path access-l 110 permit (_2400_(.+_)*3500_)|(_3500_(.+_)*2400_)
> >
> >In this example, we must find 2400 and 3500 in either order. I felt the
> >access-list below was incorrect because the (.*_)? bit meant we would
> >only match if there were zero or one other ASes between the two we care
> >about.
> >
> >Feel free to comment and maybe I'll learn something more. It does
> >strike me as odd that such a long regexp is required for something that
> >seems so straightforward at first glance.
> >
> >garnet
> >
> >On Fri, 2003-04-11 at 06:24, Ryder, Keith wrote:
> >> Use a route map but use "match 1 2"
> >> This will match only on as-path fiter 1 AND as-path filter 2.
> >>
> >> If you specify them seperately they will be as-path filter 1 OR as-path
> >> filter 2
> >>
> >> -----Original Message-----
> >> From: Daniel Cisco Group Study [mailto:danielcgs@imc.net.au]
> >> Sent: 11 April 2003 09:49
> >> To: OhioHondo; Daniel Cisco Group Study; ahmed_hassan@rayatelecom.net
> >> Cc: ccielab@groupstudy.com
> >> Subject: RE: regular express question
> >>
> >>
> >> I checked out the old thread again..... One solution would be:
> >>
> >> ip as-path access-list 1 _3500_(.*_)?2400_| _2400_(.*_)?3500_
> >>
> >>
> >> Not pretty....
> >>
> >> Daniel
> >>
> >> -----Original Message-----
> >> From: OhioHondo [mailto:ohiohondo@columbus.rr.com]
> >> Sent: Friday, 11 April 2003 12:09
> >> To: Daniel Cisco Group Study; ahmed_hassan@rayatelecom.net
> >> Cc: ccielab@groupstudy.com
> >> Subject: RE: regular express question
> >>
> >>
> >> This was a thread about a month ago. The following works as an OR
> >>
> >> ip as-path access-list 1 permit _3500_
> >> ip as-path access-list 2 permit _2400_
> >>
> >> route-map AND permit 10
> >> match as-path 1 ---- > this shows up as match as-path 1 2
> >> match as-path 2 in the config file!!! I tried this.
> >> set metric 5000
> >>
> >> As I recall, if the original solution follows the format suggested at the
> >> end of a long discussion. The original solution is shown below and
>further
> >> on in this e-mail thread.
> >>
> >> ip as-path access-list 1 permit _3550_(.*)2400_|_2400_(.*)3500_
> >>
> >>
> >>
> >> -----Original Message-----
> >> From: nobody@groupstudy.com [mailto:nobody@groupstudy.com]On Behalf Of
> >> Daniel Cisco Group Study
> >> Sent: Thursday, April 10, 2003 6:13 PM
> >> To: ahmed_hassan@rayatelecom.net
> >> Cc: ccielab@groupstudy.com
> >> Subject: RE: regular express question
> >>
> >>
> >> I believe that the as-path list will also match paths containing:
> >>
> >> "3500" and "12400"
> >> "2400" and "43500"
> >>
> >> ie the (.*) also allows other characters to appear before the 2400 or
> >> 3500...
> >>
> >> Anyone agree?
> >>
> >> Why not use something simple like:
> >>
> >> ip as-path access-list 1 permit _3500_
> >> ip as-path access-list 2 permit _2400_
> >>
> >> route-map AND permit 10
> >> match as-path 1
> >> match as-path 2
> >> set metric 5000
> >>
> >>
> >> Anything wrong with this logic?
> >>
> >> Daniel
> >>
> >>
> >> -----Original Message-----
> >> From: Ram Shummoogum [mailto:rshummoo@ca.ibm.com]
> >> Sent: Friday, 11 April 2003 2:22 AM
> >> To: ahmed_hassan@rayatelecom.net
> >> Cc: ccielab@groupstudy.com
> >> Subject: Re: regular express question
> >>
> >>
> >> Try this.
> >>
> >> ip as-path access-list 1 permit _3550_(.*)2400_|_2400_(.*)3500_
> >> !
> >> route-map AND permit 10
> >> match as-path 1
> >> set metric 5000
> >>
> >>
> >>
> >>
> >>
> >> "Ahmed Hassan" <ahmed_hassan@rayatelecom.net>@groupstudy.com on
>04/10/2003
> >> 10:35:26 AM
> >>
> >> Please respond to "Ahmed Hassan" <ahmed_hassan@rayatelecom.net>
> >>
> >> Sent by: nobody@groupstudy.com
> >>
> >>
> >> To: <ccielab@groupstudy.com>
> >> cc:
> >> Subject: regular express question
> >>
> >>
> >> Hi GROUP ,
> >> Can any one tell me how to make a regular expression that have an logical
> >> "AND" condition , for example
> >> I wan a regular expression that will filter BGP table to get expressions
> >> contain both AS2400 and AS3500 the order is not important
> >> best regards
> >>
> >> *************************************
> >> Ahmed Hassan El-shinnawy
> >> Network Planning and configuration Engineer
> >> Raya Telecom
> >> ahmed_hassan@rayatelecom.net
> >> *************************************
> >>
> >>
> >> **********************************************************************
> >> This email and any files transmitted with it are confidential and
> >> intended solely for the use of the individual or entity to whom they
> >> are addressed. If you have received this email in error please notify
> >> the system manager.
> >> This footnote also confirms that this email message has been swept by
> >> MIMEsweeper for the presence of computer viruses.
> >> www.mimesweeper.com
> >> **********************************************************************
> >>
> >>
> >> **********************************************************************
> >> This email and any files transmitted with it are confidential and
> >> intended solely for the use of the individual or entity to whom they
> >> are addressed. If you have received this email in error please notify
> >> the system manager.
> >> This footnote also confirms that this email message has been swept by
> >> MIMEsweeper for the presence of computer viruses.
> >> www.mimesweeper.com
> >> **********************************************************************
> >--
> >Garnet Ulrich
> >garnet.ulrich@gmx.net
> >
> >The secret of success is honesty and fair dealing. If you can fake
> >those, you've got it made.
> >
> >[GroupStudy removed an attachment of type application/pgp-signature which
>had a name of signature.asc]



This archive was generated by hypermail 2.1.4 : Thu May 01 2003 - 13:35:58 GMT-3