Home  >  Q&A  >  body text

ruby - 哪些语言支持扩展正则的?

就是多行带注释的。

我知道的有Ruby——需要加x选项

/\d{4}-? # 年
\d{1,2}-? # 月
\d{1, 2} # 日
/x

LiveScript——用//代替/

//
\d{4}-? # 年
\d{1,2}-? # 月
\d{1, 2} # 日
//

还有哪些?

大家讲道理大家讲道理2762 days ago651

reply all(5)I'll reply

  • 大家讲道理

    大家讲道理2017-04-21 11:21:17

    This is PCRE_EXTRA Modifier: PASSING MODIFIERS TO THE REGULAR EXPRESSION ENGINE
    Usually add X Modifier/Option/Compilation Flag
    Implementations of the PCRE series should all support this function. So you just need to see if the language has a PCRE library, or if its Regex implementation supports X Option.

    Popular language, such as,
    PHP has: http://php.net/manual/en/reference.pcre.pattern.modifiers.php
    Python also supports: http://docs.python.org/2/library/re.html#re.VERBOSE
    JavaScript does not work by default because it is not PCRE and requires the XRegExp extension: http://www.xregexp.com/
    Both Java and C# are available:
    - Java Pattern.COMMENTS
    - C# X RegExp Option

    Java and C# are available, as are JVMs such as Groovy or the .Net series.

    By the way, strictly speaking, this is not something at the language syntax level. It’s just that Ruby or JS supports RegExp literals, so in this sense there is no distinction between languages. It’s just a comparison of how to write multi-line strings in C/C++. unnatural.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-21 11:21:17

    All scripting languages ​​are supported, just extend pcre

    reply
    0
  • PHPz

    PHPz2017-04-21 11:21:17

    CoffeeScipt also supports it.

    ///
    \d{4}-? # 年
    \d{1,2}-? # 月
    \d{1, 2} # 日
    ///
    

    reply
    0
  • PHP中文网

    PHP中文网2017-04-21 11:21:17

    nark regular engine supports intersection and difference operations, and also supports multiple regular expressions: you can know which of a bunch (possibly millions) of regular expressions match in one scan.

    reply
    0
  • PHPz

    PHPz2017-04-21 11:21:17

    c and c++ are not supported

    reply
    0
  • Cancelreply