一 要实现效果如下:

   

 

 二 主要代码如下:

  const text = '文案一18890909090文案二400-8388388文案三010-1234567'
    let textArray = text.split(/(\d{3,4}-\d{7,8}|1\d{10})/)
    let textRes = []
    for (const key in textArray) {
      const flag = textArray[key] != '' && /^(\d{3,4}-\d{7,8}|1\d{10})$/.test(textArray[key])
      textArray[key] != '' && textRes.push({
        type: flag ? 'phone' : 'text',
        val: textArray[key]
      })
    }
    console.log(textRes)
   

  

posted on 2023-01-31 11:22  努力中的小白羊  阅读(36)  评论(0编辑  收藏  举报