剑轩

​js截取两个字符中间的字符串

电脑版发表于:2018/12/28 20:21

使用正则表达式来取


比如我们要取brush:js;toolbar:false 这个字符串冒号和分号中间的字符串可以

var classname = "brush:js;toolbar:false";
var substr = classname.match(/:(\S*);toolbar/);
var needcode = substr[1];
alert(needcode);

括号里边就是你需要的字符串,其实后面只使用分号也可以,但是如果字符串后面还有分号他会截图到最后第一个分号了

所以这里使用;toolbar让限定范围更广一点


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢