in reply to Re: Regexes Are Not For String Comparison
in thread Regexes Are Not For String Comparison

But I find that the simpler tools are rarely used, while the more complex ones are used oft and poorly. Many people see regexes, and never understand them; but that does not stop them from using them. And the more regexes get used by those who don't understand them, the more they seem to be mysterious giants.

I see people that put /(.*)/ in their code for no reason. It's just waiting for data to come along and break it.

japhy -- Perl and Regex Hacker

  • Comment on Re: Re: Regexes Are Not For String Comparison

Replies are listed 'Best First'.
Re: Re: Re: Regexes Are Not For String Comparison
by frag (Hermit) on Apr 24, 2001 at 21:23 UTC
    I'm not disagreeing (I think), but I'm trying to get at why people reach for the more complex ones. Using m// isn't by itself complex and is usually one of the first Way Cool Perl features taught to newbies, and people can easily think that they understand the basic regex components (like $1 or /i or $^ or .*) that they've read about or seen used in tutorials. If you're saying that people use it just to make themselves look 'leet, I don't want to discount that, but it's more than just that -- there are reasons for thinking and choosing certain things, that has to do with the way the language is structured, or in how the language is learned.

    -- Frag.

    P.S. I'm confused on the problem with /(.*)/ -- do you mean /"(.*)"/? How can copying an entire string into $1 break? (Although it is certainly dumb.)

      By asking how /(.*)/ can break, you're showing that you don't know that . can't match a newline, unless you use the /s modifier to a regex.

      And, they're doing things silly like

      if ($string =~ /.*/) { ... }
      or
      if ($string =~ /.*\.html/) { ... }
      Those show they don't know what they're doing. It's like seeing a hammer being used to pound a nail into wood, and then going around slamming a hammer into everything you see.

      japhy -- Perl and Regex Hacker

        Oop. Actually, I do know about that (and I use and know when to use /s, and /m) but I wasn't thinking of that when I read your comment. Which is still a screw-up, no excuses.

        -- Frag.