我有以下文字:
<h1>Hello world!</h1> <h2>What is {{ $slot }} Ipsum?</h2> <p><strong>Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to {{$example }}make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially {{$category1 }} unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more {{ $Product2}} recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> <p> </p><p> </p>
我尝试匹配以下模式:
{{ $slot }}
{{$example }}
{{ $Product2}}
{{$category1 }}
我当前的正则表达式如下^{{\s*$\w\s*}}
。
有人建议我在做什么错吗?
感谢您的答复!
答案 0 :(得分:2)
答案 1 :(得分:2)
您的正则表达式与您的值不匹配,因为您声明了行^
的开始,必须转义美元符号\$
才能从字面上进行匹配,并且必须使用诸如示例+
匹配一个或多个单词字符\w+
您可以使用:
{{\s*\$\w+\s*}}
说明:
{{
字面上匹配\s*
匹配空白字符零次或多次\$
匹配一个美元符号\s*
匹配空白字符零次或多次}}
字面上匹配