Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Regex Question

by keszler (Priest)
on Sep 10, 2013 at 17:07 UTC ( #1053322=note: print w/ replies, xml ) Need Help??


in reply to Regex Question

push @svcDesc, "$1:$2" while ($htmlStream->get_trimmed_text('/td') =~ +/Protocol:\s(TCP|UDP)[^\n]+Destination\sPort:\s([0-9\-]+)/g);
Note that I removed the outer set of parens in the regex.


Comment on Re: Regex Question
Download Code
Replies are listed 'Best First'.
Re^2: Regex Question
by clegane (Novice) on Sep 10, 2013 at 18:28 UTC

    This is close. I should have pointed out that each cell can contain multiple lines. The sample text I posted was one cell. I'm having trouble with greediness/unknown numbers of occurrences in a single line. One line might contain

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

    I need to extract each protocol/port pair into an array, and there's an unknown number. Protocol always comes before port, but not always immediately.

Re^2: Regex Question
by clegane (Novice) on Sep 10, 2013 at 18:41 UTC

    I've got the following going, but it's only getting the first match. If I remove the '?', it only grabs the last match. I need it to get them all. Adding a 'g' at the end doesn't seem to help

    push @svcDesc, "$1:$2" while ($htmlStream->get_trimmed_text('/td') =~ /Protocol:\s(TCP|UDP).+?Destination\sPort:\s([0-9\-]+)/);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (15)
As of 2015-07-31 16:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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









    Results (279 votes), past polls