Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

513
Vistas
How to use match() method when I have a variable dynamically with case insensitive?

Suppose I have case insensitive strings to be compared like,

const a = 'b'

const c = 'B'

So for comparing these, I used the match() method, but it works for static strings like we can use / for doing case insensitive comparison.

Eg. a.match(/b/), but I need to do it dynamically like if I have a variable, test1 = 'b' and test2 = 'B', but when doing like this test1.match(/test2/) it gets "test2" as string but I need the value('B') in it.

As I have tried like the following image

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use the RegExp constructor to make a dynamic regular expression that depends on the variable's value.

function isMatch(str, testCase) {
  var rgx = new RegExp(testCase);
  return str.match(rgx);
}

console.log(isMatch("b", "b"));
console.log(isMatch("b", "B"));
console.log(isMatch("hello world", "hello"));
console.log(isMatch("hello world", "hi"));

Check MDN for more info.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda