早教吧 育儿知识 作业答案 考试题库 百科 知识分享

正则表达式去除某个匹配字符串中间的某个字符OK,举个例子来说:aboywhowasinmyclassatschoolaboywhowasinmyclassatschool假设我想要去掉里面的空格符,该如何表达.即变成这样:aboy

题目详情
正则表达式 去除某个匹配字符串中间的某个字符
OK,举个例子来说:
a boy who was in my class at school
【a boy who was in my class at school】
假设我想要去掉【】里面的空格符,该如何表达.
即变成这样:
a boy who was in my class at school
【aboywhowasinmyclassatschool】
上句不变,下句去掉空格.
▼优质解答
答案和解析
var reg = /\s/g;
var str = 'a boy who was in my class at school';
str=str.replace(reg,'');
console.info(str)