【问题标题】:Regex Expression to match the Pattern正则表达式匹配模式
【发布时间】:2015-03-08 18:58:07
【问题描述】:

我正在尝试找出一个匹配模式的正则表达式

}

{
one or more lines here
}

i;e 一个大括号,后跟零个或多个空行,后跟一个大括号,后跟零个或多行任何文本,后跟一个大括号。

我尝试了以下方法:

/}\s*{.\n*}/

有以下解释:

} - matches the character } literally
\s* zero or more character [\r\n\t\f ]
{ matches the character { literally
. matches any character (except newline)
\n* matches 0 or more line-feed (newline)
} matches the character } literally

然而这不匹配。

请指出我做错了什么?

【问题讨论】:

    标签: regex


    【解决方案1】:
    }\s*{[^}]*}
    

    试试这个。查看演示。

    https://regex101.com/r/eS7gD7/29

    你的正则表达式

    {.\n*}

    有效量化\n 而不是.。因此它匹配a character and any number of \n's

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 2016-04-20
      • 2014-09-15
      • 2016-04-24
      • 2011-08-04
      相关资源
      最近更新 更多