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

214
Vistas
Javascript cookie.match

I have a cookie that I am trying to match it works fine on the online tool but not in the Chrome console using the [\w+]. Any help would be great.

cookie Name customerid value =2488475 

In Chrome console, I am trying document.cookie.match('customerid=document.cookie.match('customerid=([\w+])*'); but it is returning null

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

0

As Barmar said when using Regular expressions match method take //, not ''.

follow pattern string.match(regexp), So change single quotes with slash

document.cookie.match('customerid=[\w+]');
//                    ^                ^

Note: The match() method returns the matches in an array and null if no match is found.

To get a value from cookie with regex Ref:

window.getCookie = function(name) {
  var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
  if (match) return match[2];
}

In your case call the function getCookie('customerid')

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