Hi all,
I need one regular expression to match both texts. The text structure is similar, but sometimes I have a corrupted text I don't want to match.
The text1 has the
<ul>*</ul> text I need to avoid. The regular expression I have only match the text1, not the text2. I've tried some variations with | without success.
Is it possible to do what I need in just one regular expression?
Note I'm retrieving the text using the $1 and $3. I have to retrieve text using the same variables (I cannot be able to use $1 and $3 for text1 and $1 and $2 for text2).
Any help will be appreciate.
my $text1 = qq{
<div id="aaaa">
text tex text
<ul id="ccc">bla bla bla</ul>
more text
</div>
};
my $text2 = qq{
<div id="aaaa">
text text text
more text
</div>
};
my $regex = '<div id="aaaa">(.*)<ul id="ccc">(.*)</ul>(.*)</div>';
if ( $text1 =~ /$regex/sg ) {
warn "Text 1 found ".$1.$3;
}
if ( $text2 =~ /$regex/sg ) {
warn "Text 2 found ".$1.$3;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.