Q:

Do a simple seach regardless of upper an lower case

Could someone explain to me, how I can do in javascript this simple code, without taking care of upper and lower case?
if(res.search('em')!=-1){  unit='em'; res.replace(unit,'');}
if(res.search('vh')!=-1){  unit='vh'; res.replace(unit,'');}
if(res.search('px')!=-1){  unit='px'; res.replace(unit,'');}

Without any idea, that is what I have coded. It's a lot of code
if(res.search('Em')!=-1){  unit='Em'; res.replace(unit,'');}
if(res.search('eM')!=-1){  unit='eM'; res.replace(unit,'');}
if(res.search('EM')!=-1){  unit='EM'; res.replace(unit,'');}
...

I'm sure there is a better way to do that!?
Thanks a lot.

A:

For the first part you can use toLowerCase()
if(res.toLowerCase().search('em') != -1)
You can use alternation in regex alongside case insensitive flag.
/(em|vh|px)/i Mathces em or vh or px.

function replaceUnit(input){
  return input.replace(/(em|px|vh)/i ,'replaced')
}

console.log(replaceUnit('height: 20em'))
console.log(replaceUnit('width:=20Em'))
console.log(replaceUnit('border-radius: 2Px'))
console.log(replaceUnit('unit=pX'))
console.log(replaceUnit('max-height=20Vh'))

