Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: combine two-part regex test

by AltBlue (Chaplain)
on Jan 30, 2007 at 00:24 UTC ( [id://597229]=note: print w/replies, xml ) Need Help??


in reply to combine two-part regex test

fancy experimental features? ;-)
#!/usr/bin/perl -l use strict; use warnings; my @str = split /\n/, <<'HTML'; <tr class="meld"><th>Security Code Matched</th><td>foo</td></tr> <tr><th>Security Code Matched</th><td>N/A</td></tr> <tr><th class="foo">Security Code Matched</th><td>N/A</td></tr> <tr><th>Security Code Matched</th><td>10!</td></tr> <tr><td>Security Code Matched</td><td class="val">N/A</td></tr> HTML for (@str) { if ( m{ \bSecurity\ Code\ Matched\b (.*?)</tr> (?(?{ index($^N, 'N/A') < 0 })!) }xsg ) { print "[[$_]]"; } }
output:
[[<tr><th>Security Code Matched</th><td>N/A</td></tr>]] [[<tr><th class="foo">Security Code Matched</th><td>N/A</td></tr>]] [[<tr><td>Security Code Matched</td><td class="val">N/A</td></tr>]]
i wouldn't use it at home, though ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-06-15 10:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.