Helpful Information
 
 
Category: Regex Programming
How to eliminate some string using regex?

My curl function returned some html tags and part of it was :

<span class="descBold">1<span class="null">9999</span>2<span class="null2">8888</span><span class="null3">7777</span><span class="null4">5555</span><span class="notnull">3</span></span>

given the above tags i want to get as output the numbers highlighted as bold (123), and eliminate or ignore other numbers that uses the span with classes like "null", "null2", "null3" and "null4".

Can some one here help me with this problem?

Kind Regards,
Rommel

Since your HTML is so weirdly formed, I couldn't find a decent way to do this with a pure regexp. Here's a PHP implementation:

$string = '<span class="descBold">1<span class="null">9999</span>2<span class="null2">8888</span><span class="null3">7777</span><span class="null4">5555</span><span class="notnull">3</span></span>';
preg_match_all("/<span( class=['\"](.+?)['\"])?>([^<]+)/", $string, $foo);
foreach ( $foo[2] AS $key => $className ) {
if ( substr($className, 0, 4) != 'null' ) {
echo $foo[3][$key] . "\n";
}
}Outputs 1 and 3

-Dan










privacy (GDPR)