Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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 answers
Answer question

0

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

I guess this is what you want

about 4 years ago · Juan Pablo Isaza Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!