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

186
Views
Regex detect last character slash and and ?id=

This is my Javascript regex ^.*(?<!\/)$ that checks if the URL is not ending with (/) slash

detects: /play/popular ok: /play/popular/

How can I detect if the URL is not ending with / and does not include ?id= ?

detects: play/popular catch: play/popular/?id=448

debugger: https://regex101.com/r/sSDIic/2

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

One way is to extend the negative lookbehind to optionally add the id= followed by 1 or more digits.

^.*$(?<!\/(?:\?id=\d+)?)

Regex demo

It might be easier to rule out id= in the string using a negative lookahead, and match a non whitespace char at the end being not a /if it can not end on a space.

^(?!.*\?id=).*[^\s/]$

Regex demo

Note that .* also match spaces, to match only non whitespace characters you can use \S*

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!