Differences between Ruby 1.9 and Javascript regexp

后端 未结 1 519
清歌不尽
清歌不尽 2020-12-30 10:35

Apart from Javascript\'s ^ and $ being equivalent to Ruby\'s \\A and \\z, what other subtle differences are there between

相关标签:
1条回答
  • 2020-12-30 10:46

    Features supported by Ruby, but not JavaScript:

    • \a (bell)
    • \e (escape)
    • \A (start of string)
    • \Z (end of string, before final line break)
    • \z (end of string)
    • Forward references \1 through \9
    • Backreferences to failed groups also fail
    • (?>regex) (atomic group)
    • \G (start of match attempt)
    • (?#comment)
    • Free-spacing syntax supported
    • Character class is a single token
    • # starts a comment
    • [:alpha:] POSIX character class
    • (?i) (case insensitive) (JavaScript supports /i only)
    • (?s) (dot matches newlines) (?m)
    • (?m) (^ and $ match at line breaks) (/m only in JavaScript)
    • (?x) (free-spacing mode)
    • (?-ismxn) (turn off mode modifiers)
    • (?ismxn:group) (mode modifiers local to group)

    Features supported by JavaScript, but not Ruby:

    • \cA through \cZ (control character)
    • \ca through \cz (control character)
    • \u0000 through \uFFFF (Unicode character)

    Source:

    • http://www.regular-expressions.info/refflavors.html
    0 讨论(0)
提交回复
热议问题