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

155
Visualizações
Write regex for testing a param is present in URL

I have the following reg ex and I am new to this: https:\/\/www.google-analytics.com\/.*

And the strings I am using to test are:

https://www.google-analytics.com/collect?v=1&ec=click&ea=test
https://www.google-analytics.com/collect?v=1&ea=tes

Currently, both strings will pass this check as I am doing /.* at the end of the regex, but what I want is this should check for ec=click param only and the ONLY the first test string should pass (https://www.google-analytics.com/collect?v=1&ec=click&ea=test)... does anyone know how I can do this?

Link to playground: https://regex101.com/r/mIjGjD/1

Thank you in advance

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

https:\/\/www.google-analytics.com\/(.*)&ec=click(.*)

I guess this is what you want

about 4 years ago · Juan Pablo Isaza Relatório

0

This regex should work. Notice that I add a map function in order to get all possible matches in an array of urls

const urls = [
"https://www.google-analytics.com/collect?v=1&ec=click&ea=test",
"https://www.google-analytics.com/collect?v=1&ea=test"
];

const reg = /https:\/\/www\.google-analytics\.com\/.*&ec=click.*/;

const matches = urls.map(url => url.match(reg) || []).flat();

console.log(matches)

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