Vue regular expression replacement

clipboard.png
the requirement is that the AutoComplete component of Vue input abc will go to the background to take out all the existing abc (case-insensitive) and highlight

highlightData: function (data, propShow, propOrigin, highlight) {
        data.forEach(item => {
          // 
          let replaceReg = new RegExp(highlight, "gi")
          // v-html
          let replaceString = "<span class="color-primary">" + highlight + "</span>"
          // 
          item[propShow] = item[propOrigin].replace(replaceReg, replaceString)
        })
        return data
      },

that"s what I wrote before, but it turns the original ABC into abc and highlights it. It"s hard? How to write


Why use replace? I think we should use test or match. Of course, it's not impossible for you to use replace.
let replaceReg = new RegExp (highlight, 'gi')
let replaceString =' < span class= "color-primary" > $& '
item [propShow] = item [propOrigin]. Replace (replaceReg, replaceString)


but this will turn the original ABC into abc and highlight
'abcABC'.replace(/abc/gi,(val) =>`

${val}

`) //"

abc

ABC

"
Menu