Converting PHP Regex's to Javascript (or what are the differences?)

后端 未结 2 823
离开以前
离开以前 2020-12-21 09:32

I have a form generator that uses (perl compatible) regexes for ther backend validation. Since the whole form is being dynamically generated it was fairly trivial to add a

相关标签:
2条回答
  • 2020-12-21 10:09

    PHP preg_* functions and JavaScript both use Perl-compatible regular expressions. In principle, they should support the same set of regular expressions.

    You really should give some examples of what is not working, because it is very likely that your problem is due to escaping/string handling.

    0 讨论(0)
  • 2020-12-21 10:10

    Read about specific implementation details for Regular Expressions in Javascript.

    JavaScript implements Perl-style regular expressions. However, it lacks quite a number of advanced features available in Perl and other modern regular expression flavors

    For one thing, the / character denotes the beginning and end of a regex in Javascript, so you might need to escape it, but that depends on how you're instantiating the regular expression in Javascript (with the literal notation or the RegExp class).

    0 讨论(0)
提交回复
热议问题