js去掉头尾空格、括号

去掉头尾空格

trimSpace = (str: string) => {
    const reg = /^\s+|\s+$/g;
    return str.replace(reg, "");   
  }

去掉括号中的内容

trimBrackets = (str: string) => {
    const reg = /\([^\)]*\)/g;
    return str.replace(reg, "");    
  }

获取括号中的内容

trimBrackets = (str: string) => {
    const reg = /\([^\)]*\)/g; 
    const strNew = str.substr(str.indexOf("(")+1);
    return strNew.substr(0,strNew.indexOf(")"));   
  }

 

你可能感兴趣的:(前端,javascript)