Aaaagh! Simple RegExp Help Needed

J

Jeff

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

Jürgen Exner

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,171
Messages
2,570,934
Members
47,472
Latest member
KarissaBor

Latest Threads

Top