有些语言具有在长正则表达式中嵌入换行符和空格的功能,以使它们更具可读性
- ( yogi | booboo ) # match something
- \s
- ( the \s)? # optional article
- bear # bears are not Mr. Ranger
AFAICT golang没有那个选项,是吗?
缺乏这一点,composed regex是明确的唯一选择吗?还是有另一个成语?我现在没有找到任何长regexen的例子.
大多数时候,人们只是提供评论,其中描述了正则表达式匹配的内容.但是浏览Go源代码我发现了
this个有趣的例子:
- // 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)` +
- `)`,)