加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – 用于编写长正则表达式,嵌入式注释的习语?

发布时间:2020-12-14 06:25:48 所属栏目:百科 来源:网络整理
导读:有些语言具有在长正则表达式中嵌入换行符和空格的功能,以使它们更具可读性 ( yogi | booboo ) # match somethings( the s)? # optional articlebear # bears are not Mr. Ranger AFAICT golang没有那个选项,是吗? 缺乏这一点,composed regex是明确的唯一
有些语言具有在长正则表达式中嵌入换行符和空格的功能,以使它们更具可读性
( 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)*?nn)` +

    // 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)` +

    `)`,)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读