Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Regex Question

by talexb (Canon)
on Sep 10, 2013 at 18:07 UTC ( #1053329=note: print w/ replies, xml ) Need Help??

in reply to Regex Question

When dealing with regular expressions, my approach is to do the simplest thing that works.

In your case, this means looking for three capital letters, following by some stuff, and then a two or three digit number, a dash, and the same two or three digit number.

So the regexp I'd use would be

This makes the assumption that the two numbers at the end are the same. If they might be different, you'd have to change the second capture to something like
When in doubt, try the simplest thing that could work. You're putting 'Protocol' and other stuff in there -- throw it away -- you don't need it. :)

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Comment on Re: Regex Question
Select or Download Code
Re^2: Regex Question
by Anonymous Monk on Sep 10, 2013 at 18:30 UTC
    ... and/or do it in stages: write one regex to grab an entire-line and then a second regex to break down what the first one grabbed.
Re^2: Regex Question
by clegane (Novice) on Sep 10, 2013 at 18:32 UTC

    Talexb, thanks for the reply. Please see my other reply to keszler. The protocol and destination ports are in there b/c that's how I can pick them out. The data can follow this structure:

    something, Protocol: UDP, something, Destination Port: x-y, something, something, Protocol: TCP, something, Destination Port: a-b, something

    So, reliably picking them out can be challenging without the field names. Also, this data I'm working with doesn't always follow this format, so I'm needing to ignore the data that doesn't.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1053329]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2015-07-04 16:42 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (60 votes), past polls