正则 exec函数

    //  检测类型 返回你字符串 这样的格式 [123][123][123] 没有,作为分割 所以不能用 split分割成数组 下面用正则 匹配
    formatText (contentObj) {
      const TEXT_EMO = /\[[^\[\]]+\]/g
      let content = String(contentObj)
      let result
      while ((result = TEXT_EMO.exec(content)) != null) {
        console.log(result)
      }
      return contentObj
    }
     this.formatText('[123][123][123]')
exec 检索字符串中指定的值。返回找到的值,并确定其位置。 而 test 则是返回布尔值 true与false

 

posted @ 2019-01-01 15:59  xuanPhoto  阅读(186)  评论(0)    收藏  举报