示例字符串:
{{--
some text
--}}
我正在尝试匹配{{ - 包括第一个 - }之间的任何内容 它还需要捕获回报和换行符。
我试过这样的事情:\{\{--[^\r\n]--\}\}
它似乎捕捉了括号之间的所有内容,但我也无法弄清楚如何捕捉括号。
修改 我正在尝试修改一个sublime文本插件,为laravel的刀片模板添加语法hilighting。如下所述:'({{ - [\ s \ S] * - }})'匹配我想要匹配的内容。括号可能被不同的规则所覆盖。
答案 0 :(得分:2)
您可以使用此正则表达式:
(\{\{--[\s\S]*--\}\})
<强>解释强>
1st Capturing group (\{\{--[\s\S]*--\}\})
\{ matches the character { literally
\{ matches the character { literally
-- matches the characters -- literally
[\s\S]* match a single character present in the list below
Quantifier: Between zero and unlimited times, as many times as possible,
giving back as needed [greedy]
\s match any white space character [\r\n\t\f ]
\S match any non-white space character [^\r\n\t\f ]
-- matches the characters -- literally
\} matches the character } literally
\} matches the character } literally