Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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

Replies are listed 'Best First'.
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.

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1053329]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2018-05-23 10:06 GMT
Find Nodes?
    Voting Booth?