有些语言具有在长正则表达式中嵌入换行符和空格的功能,以使它们更具可读性
( 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)` + `)`,)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。