Home: Perl Programming Help: Regular Expressions:
.+? probs...



AndyNewby
Novice

May 24, 2003, 4:21 AM


Views: 15042
.+? probs...

Hi...I have the following text;

<h2>WASHINGTON, May 23 (AFP) -</h2> US soldiers in Iraq seized a truck believed to be loaded with 2,000 gold bars worth as much as 500 million dollars during a ...

I am trying to remove the following;

<h2>WASHINGTON, May 23 (AFP) -</h2>

I have tried;

$back =~ s,<h2>(.+?)</h2>,,i

....and...

$back =~ s,<h2>.+</h2>,,i

... and ...

$back =~ s,<h2>?</h2>,,i

None of these seem to remove it. Am I doing it wrong, or is it just a problem with caching on my server, so I do not see the updates?

Cheers

Andy


Paul
Enthusiast

May 24, 2003, 7:04 AM


Views: 15039
Re: [AndyNewby] .+? probs...

Caching? Wink

$html =~ s|<h2>.+?</h2>||si;

...should work fine. If not, its something else in your code.


AndyNewby
Novice

May 24, 2003, 9:19 AM


Views: 15036
Re: [Paul] .+? probs...

Didn't work Frown

Still giving stuff like this back;

UNITED NATIONS, May 23 (AFP) - UN Secretary General Kofi Annan has chosen Sergio Vieira de Mello, currently the UN High Commissioner for Human Rights, as his special representative ... [more]


...and...

CRAWFORD, Texas, May 23 (AFP) - US President George W. Bush on Friday fueled speculation he may convey his first Middle East summit next month, saying he would meet ... [more]


Cheers

Andy
webmaster@ace-installer.com
http://www.ace-installer.com


Jasmine
Administrator

May 24, 2003, 3:54 PM


Views: 15034
Re: [AndyNewby] .+? probs...

Paul's answer worked for me as well:

$html =~ s|<h2>.+?</h2>||si;

Of the ones you provided, these worked:
$back =~ s,<h2>(.+?)</h2>,,i
$back =~ s,<h2>.+</h2>,,i

This one didn't because the ? was making the > optional and not looking for anything in between the h2 tags:
$back =~ s,<h2>?</h2>,,i


AndyNewby
Novice

May 26, 2003, 2:26 AM


Views: 15027
Re: [Jasmine] .+? probs...

Thanks. I got it working now. It was a stupid mistake (I had removed the <h2> tags *before* the regex.....lol)

Cheers

Andy
webmaster@ace-installer.com
http://www.ace-installer.com