You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varperson={name: 'sofish',bio: 'a programmer'};vartmpl='This is {name} and he is {bio}.';varoutput=tmpl.replace(/\{(\w+)\}/g,function(match,group1){returnperson[group1]||'';});console.log(output);
在处理字符串的时候,正则就非常有用。今天老婆又开始看文章了,所以我也开始更新了。举个例子,处理模板,在没有多行模板的时候,我通常会选择这样做:
关于正式的基础,字面量、ExpReg 对象,
exec
test
search
match
replace
等方面的使用,可以看这篇文章:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_ExpressionsThe text was updated successfully, but these errors were encountered: