写成长正则表达式,嵌入式注释的成语?

Kev*_* G. 9 regex go

有些语言具有在长正则表达式中嵌入换行符和空格的功能,以使它们更具可读性

( yogi | booboo )   # match something
\s
( the \s)?          # optional article
bear                # bears are not Mr. Ranger
Run Code Online (Sandbox Code Playgroud)

AFAICT golang并没有这样的选择,是这样吗?

缺乏这一点,组合正则表达式是唯一明确的选择吗?还是有另一个成语?我现在没有找到任何长regexen的例子.

Ain*_*r-G 8

大多数时候,人们只是提供评论,其中描述了正则表达式匹配的内容.但是通过Go源代码略读我发现了这个有趣的例子:

// removeRE is the list of patterns to skip over at the beginning of a
// message when looking for message text.
var removeRE = regexp.MustCompile(`(?m-s)\A(` +
    // Skip leading "Hello so-and-so," generated by codereview plugin.
    `(Hello(.|\n)*?\n\n)` +

    // Skip quoted text.
    `|((On.*|.* writes|.* wrote):\n)` +
    `|((>.*\n)+)` +

    // Skip lines with no letters.
    `|(([^A-Za-z]*\n)+)` +

    // Skip links to comments and file info.
    `|(http://codereview.*\n([^ ]+:[0-9]+:.*\n)?)` +
    `|(File .*:\n)` +

    `)`,
)
Run Code Online (Sandbox Code Playgroud)