Gossamer Forum
Home : General : Perl Programming :

Nuvver blummin regex...

Quote Reply
Nuvver blummin regex...
Hi folks,

I'm trying to help out a guy on one of the dbMan forums there, but I need a regex that will recognise BODY and /BODY tags. That is, the first one would match "<BODY" in upper or lower case, followed by the rest of the tag which can be ignored, and the second would match "</BODY>" in upper or lower case.

Cheers,
adam
Quote Reply
Re: Nuvver blummin regex... In reply to
Hi Mark,

Can I use that in this context:

if ($line =~ m!</?body(.+)?>!i) {
do_something; }

or this:

if (!$line =~ m!</?body(.+)?>!i) {
do_something; }

or do I have to change =~ to check for a negative return?

Thanks for your help...

adam
Quote Reply
Re: Nuvver blummin regex... In reply to
This could work for you:

$tag =~ m!</?body(.+)?>!i

but it is a bit rudimentary and may not work for all situations. Though I did just run it through a few checks and it seems to be ok. It will work for <BODY> or </BODY> (both case insensitive, and will allow other info after BODY)

It should be a start for you, at least.

--mark
Quote Reply
Re: Nuvver blummin regex... In reply to
you can use it like that! Smile

Example

Code:
$line = "<body>";
if ($line =~ m!</?body(.+)?>!i) {
print "Yup, Body tag is in there\n";
} else {
print "Nope, not in there\n";
}
Smile

--mark

[This message has been edited by Mark Badolato (edited May 23, 1999).]
Quote Reply
Re: Nuvver blummin regex... In reply to
Thanks very much Mark, you're a prince amongst men!

Smile

adam