Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Aaaagh! Simple RegExp Help Needed

Reply
Thread Tools

Aaaagh! Simple RegExp Help Needed

 
 
Jeff@aetherweb.co.uk
Guest
Posts: n/a
 
      05-25-2005
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

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      05-25-2005
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


 
Reply With Quote
 
 
 
 
Jeff@aetherweb.co.uk
Guest
Posts: n/a
 
      05-25-2005
YAAAAAAAAAAAAAAAAAAAAY!!!

Thank you!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
simple regexp help needed - pull phrase out of string Max Williams Ruby 5 10-10-2008 01:23 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp.exec() returns null when there is a match - a JavaScript RegExp bug? Uldis Bojars Javascript 2 12-17-2006 09:50 PM



Advertisments