Oops, I think you confused me with someone else.  I did not ask this
question.

Shawn




                                                                                       
                            
                    [EMAIL PROTECTED]                                                      
                            
                    g                    To:     [EMAIL PROTECTED]                    
                            
                                         cc:                                           
                            
                    08/20/2002           bcc:    Shawn Milochik/US/GODIVA/CSC          
                            
                    04:43 PM             Subject:     Re: Regex to split router 
ifDescr up                         
                                                                                       
                            
                                                                                       
                            





Shawn wrote:
>
> So, I have an interesting question and a bit of code. I didn't really
> know whether this was the right forum or not, but here goes.
>
> I have two goals I would like help with:
>   1. Optimize/simplify the regex
>   2. Recognize where the regex would produce false positives on some
>      ifDescrs which don't actually have a real hardware path
>
> Really, #1 is most befitting this mailing list, but if anyone wants to
> help with #2 that's great.
>
> For those of you who are famimliar, a cisco router's SNMP ifDescr can
> contain what i would describe as the hardware path of whatever interface
> you are querying. For example, "Ethernet1/0", "T3 3/0/2", "POS2/0/1".
> Juniper routers have a similar thing.
>
> Now, I have the following regex to split these up into four pieces.
> /^([^0-9]+)([0-9]+ |)([0-9]+\/[^\s]+)(.*)$/
>         $1 : Is a required match of some non-numeric chars. This would
>              match "Ethernet", or the "T" in T3 or T1
>         $2 : An optional match which would catch the "3 " in ifDescrs
>              like "T3 3/0/1"
>         $3 : string starting with one or more numerics, then a "/", then
>              all non-whitespace
>         $4 : the rest
>
> In all cases I've seen, the text before the hardware path will only end
> in a numeric char if there is a space terminating it. Hence, "T3 3/0/2"
> returning $3 == "3/0/2" and "Ethernet0/1" returning $3 == "0/1".
>
> Now, can anyone see how the regex could be simplified?

You can use \d instead of [0-9], \D instead of [^0-9] and \S instead of
[^\s].

/^(\D+)(\d+ |)(\d+\/\S+)(.*)$/



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






**********************************************************************
This e-mail and any files transmitted with it may contain 
confidential information and is intended solely for use by 
the individual to whom it is addressed.  If you received
this e-mail in error, please notify the sender, do not 
disclose its contents to others and delete it from your 
system.

**********************************************************************


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to