Home > Archive > PERL Miscellaneous > May 2005 > Aaaagh! Simple RegExp Help Needed
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Aaaagh! Simple RegExp Help Needed
|
|
| Jeff@aetherweb.co.uk 2005-05-25, 3:56 pm |
| Hi,
I write fairly complex regexps on a daily basis (complex to me anyway)
but I didn't get much sleep last night and I think that's why this one
is doing my nut. I can't for the life of me work out why:
my $test = "Lalalala <head>this is the \nhead zone\n\n<other
tag></other tag>\n\n<!--lalalala-->\n</head> totototot";
$test =~ s/<head>.*<\/head>//;
Doesn't strip out everything between and including the
<head>....</head> HTML tags.
I know it's not the most robust regexp. It's a simplified form of what
I actually want, but it best illustrates my point.
I'm missing something obvious I know... but what?
Thanks,
Jeff
| |
| Jürgen Exner 2005-05-25, 3:56 pm |
| Jeff@aetherweb.co.uk wrote:
> I write fairly complex regexps on a daily basis (complex to me anyway)
> but I didn't get much sleep last night and I think that's why this one
> is doing my nut. I can't for the life of me work out why:
>
> my $test = "Lalalala <head>this is the \nhead zone\n\n<other
> tag></other tag>\n\n<!--lalalala-->\n</head> totototot";
> $test =~ s/<head>.*<\/head>//;
>
> Doesn't strip out everything between and including the
> <head>....</head> HTML tags.
>
> I know it's not the most robust regexp. It's a simplified form of what
> I actually want, but it best illustrates my point.
>
> I'm missing something obvious I know... but what?
You are missing that your string contains multiple lines and . doesn't match
a newline unless you specify the s modifier.
jue
| |
| Jeff@aetherweb.co.uk 2005-05-25, 3:56 pm |
| YAAAAAAAAAAAAAAAAAAAAY!!!
Thank you!
|
|
|
|
|