in reply to Re: Should I escape all chrs in a regex?
in thread Should I escape all chrs in a regex?

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.
  • Comment on Re^2: Should I escape all chrs in a regex?

Replies are listed 'Best First'.
Re^3: Should I escape all chrs in a regex?
by Anonymous Monk on Sep 29, 2010 at 06:40 UTC
    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.

Re^3: Should I escape all chrs in a regex?
by chromatic (Archbishop) on Sep 29, 2010 at 15:12 UTC
    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.)