how can I extract contents of several () from one message ?-traceroute and regex

Jun 20, 2010 at 5:35pm

how can I extract contents of several () from one message ?-traceroute and regex

Sorry, it’s about regexp still and again…
I’d like to use the traceroute shell to estimate the journey of net infos.

Everything works fine until there are several ip addresses in the same line of my zl queue… Then regexp doesn’t understand anything…

How could I output ip adresses from for exemple: “(90.12.34.x) bla bla (90.x.x.x)” ?
Here’s my patch:
max v2;
#N vpatcher 0 44 1680 1046;
#P origin 35 0;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 586 385 32 196617 print;
#P newex 646 702 82 196617 jit.str.tosymbol;
#P newex 646 735 62 196617 prepend set;
#P window linecount 0;
#P message 646 761 16 196617;
#P window linecount 1;
#P newex 697 216 53 196617 closebang;
#P newex 495 818 62 196617 prepend set;
#P message 697 271 27 196617 pkill;
#P newex 564 363 31 196617 shell;
#P message 564 271 108 196617 traceroute yahoo.com;
#P newex 560 786 46 196617 zl queue;
#P number 598 813 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 81 559 69 0;
#P window setfont “Sans Serif” 24.;
#P window linecount 0;
#P message 493 851 27 196632;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 564 557 95 196617 jit.str.fromsymbol;
#P newex 564 675 194 196617 jit.str.regexp @re [.]*\\((.*)\\)[.]*;
#P window setfont “Sans Serif” 20.;
#P comment 153 576 354 196628 < < #P window linecount 3;
#P comment 1041 294 390 196628 Everything is fine until there are several ip addresses on the same line , then regexp is dying !;
#P objectname ;
#P connect 11 0 4 0;
#P connect 7 0 11 0;
#P connect 15 0 7 0;
#P connect 5 0 7 0;
#P connect 8 0 9 0;
#P connect 10 0 9 0;
#P connect 9 0 3 0;
#P connect 3 0 2 0;
#P connect 9 0 16 0;
#P connect 7 1 6 0;
#P connect 2 2 15 0;
#P connect 15 0 14 0;
#P connect 14 0 13 0;
#P connect 12 0 10 0;
#P pop;

And sorry about this regepx noise again !

#50984
Jun 20, 2010 at 5:51pm

Every time I try to open your patch max hangs until I force quit. Might be a problem at my end rather than with your patch. If you’re trying to grab multiple IP addresses from the same line of input you could use something like:

\(([0-9|.]{7,15})\)

It is not a failsafe method as it looks for any combination of numbers and periods but as long as you’re fairly sure the addresses will be formatted properly it should fit your needs. Be sure to use the backreferences output.

lh

#182873
Jun 20, 2010 at 5:57pm

Cool! Thx, that works.
Can you explain why it does work ?
Thank you, no problem of opening my patch here.
Merci ,
Ad

#182874
Jun 20, 2010 at 6:12pm

\( a literal opening bracket
( start our reference
[0-9|.] any number or a literal period
{7,15} repeated between 7 and 15 times
) stop our reference
\) a literal closing bracket

The object will then output any matches from the input from the backreferences outlet, even multiple instances. We haven’t specified a whole string, just the part we are actually looking for. You might need to be careful as it will match invalid IP addresses such as:

………
1234567890
137.0.0.1

As long as it is made of numbers and periods and isn’t too short or too long it will be reported.

lh

#182875
Jun 20, 2010 at 10:09pm

Thx dear !
Ad

#182876

You must be logged in to reply to this topic.