要找的在每一场比赛中运行的一个函数,就像ruby那样:
"hello _there_".gsub(/_.*?_/) { |m| "<div>" + m[1..-2] + "</div>" }
或能够引用一个匹配的组:
"hello _there_".gsub(/_(.*?)_/, "<div>\\1</div>")
发布于 2018-01-16 07:03:53
可以用replace而不是gsub...
replace
gsub
"hello _there_".replace(/_(.*?)_/g, "<div>\$1</div>")
发布于 2018-01-16 06:12:43
"hello _there_".replace(/_(.*?)_/, function(a, b){ return '<div>' + b + '</div>'; })
或者也可以:
"hello _there_".replace(/_(.*?)_/, "<div>$1</div>")
相似问题
领取专属 10元无门槛券
AI混元助手 在线答疑
洞察 腾讯核心技术
剖析业界实践案例