如何更改正则表达式以使子字符串也包含DOT,例如:
我确实想匹配{{
和}}
之间的所有子字符串
当此子字符串不包含.
时,正则表达式工作正常:
"When he come, {{person}} will give his son {{something}}".match(/{{(w*)}}/g) ;
结果:
现在,如果此子字符串包含.
(点),则regex不会按预期工作:
"When he come, {{person.firstname}} will give his son {{something}}".match(/{{(w*)}}/g) ;
结果:
如何更改正则表达式以使子字符串也包含DOT,例如:person.firstname
或使用此模式匹配{{
和}}
之间的任何内容
{{([^}]*)}}
解释:
[^}] a character class, anything but "}"
w
将仅与a-z, A-Z, 0-9, _
匹配。http://www.w3schools.com/jsref/jsref_regexp_wordchar.asp.
使用这个正则表达式也可以包括任意数量的点:
/{{([w.]*)}}/g