Answers for "substitute multiple strings"

0

substitute multiple strings

const mapObj = {
  'style="font-weight: 300;"': '',
}

function substiteStrings(str: string, mapObj: { [x: string]: string }) {
  const exReg = new RegExp(Object.keys(mapObj).join('|'), 'gi')

  return str.replace(exReg, function (matched: string) {
    return mapObj[matched]
  })
}
Posted by: Guest on April-13-2022

Code answers related to "substitute multiple strings"

Browse Popular Code Answers by Language