Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda