in reply to Re: Re: Re: Re: How do I use regex to strip out specific characters in a string?
in thread How do I use regex to strip out specific characters in a string?

I suspect it is personal preference. However, any time someone is using a regex to parse out a line of text, I start itching to rewrite. That's just getting too fancy-schmancy for maintainable code ... in my opinion. (I don't want to start a crusade here!)

------
/me wants to be the brightest bulb in the chandelier!

Vote paco for President!

  • Comment on Re{5}: How do I use regex to strip out specific characters in a string?

Replies are listed 'Best First'.
Re: Re{5}: How do I use regex to strip out specific characters in a string?
by Sifmole (Chaplain) on Aug 23, 2001 at 01:14 UTC
    What would you consider a good use of a regex?
      There are generally three reasons I'd use a regex.
      1. To check if a given string has a given pattern that goes beyond substr. Generally, I'll use this in the form next LOOP if /REGEX/;
      2. To do a substitution that goes beyond substr.
      3. To grab a substring if I don't know where in the string it starts. This is often quicker and more maintainable than using index and substr.
      Unless it's extremely simple, I never use a regex to parse data in something I ever intend someone (including me) to read in the future. The big thing here is that most programmers will easily understand unpack or substr, cause those exist in other C-type languages. However, most programmers will have difficulty understanding most complex regexes.

      This isn't to say that a regex shouldn't be used for parsing complex data. Just be aware that someone coming to your code without the benefit of your knowledge may need to be able to maintain it. I'm all for forcing people to learn new stuff, but the learning curve shouldn't be too steep.

      ------
      /me wants to be the brightest bulb in the chandelier!

      Vote paco for President!