Aaaagh! Simple RegExp Help Needed

Discussion in 'Perl Misc' started by Jeff@aetherweb.co.uk, May 25, 2005.

  1. Guest

    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
     
    , May 25, 2005
    #1
    1. Advertising

  2. 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
     
    Jürgen Exner, May 25, 2005
    #2
    1. Advertising

  3. Guest

    YAAAAAAAAAAAAAAAAAAAAY!!!

    Thank you!
     
    , May 25, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean Smitz

    Help needed with Regexp Class

    Sean Smitz, Mar 5, 2007, in forum: Ruby
    Replies:
    2
    Views:
    95
    Sean Smitz
    Mar 5, 2007
  2. regexp help needed

    , Apr 27, 2007, in forum: Ruby
    Replies:
    4
    Views:
    101
  3. Brubix

    Regexp help needed

    Brubix, May 1, 2008, in forum: Ruby
    Replies:
    3
    Views:
    81
    Brubix
    May 2, 2008
  4. Max Williams
    Replies:
    5
    Views:
    97
    Max Williams
    Oct 10, 2008
  5. Joao Silva
    Replies:
    16
    Views:
    402
    7stud --
    Aug 21, 2009
Loading...

Share This Page