Any advice is appreciated
There have been already good and solid solutions, but on a regex thread, I can't just sit on my hands ;-)
I like johngg's solution and tried to fancify his code further:
... my $data = ' Timed out (reason: in while loop) ::expect_out(0,string) = > ::expect_out(1,string) = RF use CSWT#RF### dis qremote(MQSI.3PL846) RNAME1 : dis qremote(MQSI.3PL846) RNAME AMQ8409: Display Queue details.QUEUE(MQSI.3PL846)TYPE(QREMOTE)RNAME(MQ +SI.3PL846) No commands have a syntax error. AMQ8409: Display Queue details.QUEUE(MQSI.3PL944)TYPE(QREMOTE)RNAME(MQ +SI.3PL944) end2 : end '; my $match = qr/^AMQ8409 .+? (Q.+?(\w+)\)) .+? (R.+?\2\)) /mx; for( split /\n/, $data ) { print "$1 ----> $3\n" if /$match/ } ...
... but the question here is: Is there a speed requirement, e.g. do you have to parse some 100 MB and spit out the results in one second? Then, all the solutions so far (including mine) would look rather bad (slow), because they depend heavily on (.+?) or (.*?).
Regards
mwa
In reply to Re: capturing words
by mwah
in thread capturing words
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |