in reply to Should I escape all chrs in a regex?

Perl 5 regex syntax isn't going to change in such a way that your code suddenly breaks. If there are ever any incompatible changes, they won't be on by default.

(Backwards compatibility is such a constraint on Perl 5 development that a significant percentage of the Perl 5 parser—and you know how complex that parser must be—exists solely to support the Perl 1 style of invoking functions with do subname(). Has anyone ever seen that in use in Perl 5?)

Replies are listed 'Best First'.
Re^2: Should I escape all chrs in a regex?
by MikeKulls (Novice) on Sep 29, 2010 at 05:50 UTC
    While that might be true what happens if we go to perl 6 and they break backwards compatibility? Or someone moves the regex over to some new version of PHP or puts it into C#? I know it's very unlikely to be an issue but isn't it better to be sure? Besides, it is quite possible for all I know that > does have some special meaning and I don't know about it.
      While that might be true what happens if we go to perl 6 and they break backwards compatibility?

      The perl5-to-6 migration tools will know how to compensate

      Or someone moves the regex over to some new version of PHP or puts it into C#?

      perl regular expressions are unique, moving to a different language is not a straight cut/paste operation, so that someone will have to live with the fallout; an extra character is not protection.

      I know it's very unlikely to be an issue

      As the old sayings go

      • if it ain't broke...
      • doctor it hurts when I ...
      Its only an issue if you choose to make it an issue by switching languages, or upgrading to incompatible versions ....

      but isn't it better to be sure?

      The way you make sure is to trust but verify, meaning write a test suite.

      I know it's very unlikely to be an issue but isn't it better to be sure?

      You're not sure. Randomly throwing extra backslashes into your regular expression because you worry that someday someone might port the code to a different regular expression engine that you don't know about right now (and you can't predict which regex engine that is or when this might happen) is superstition. Is that the best use of your time?

      Besides that, the substantive differences in a different language or a different version of Perl are more important and they'll require more work and more thinking than surface-level syntax.

      (Besides that, Perl 6 has a Perl 5 regex compatibility mode.)