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

204
Views
Need help in writing Regular expression

Can someone help me in writing regular expression to match such kind of string

Rules are:

  1. It should start with nl
  2. It can or cannot have one parameter in between nl and contact (like /abc/) but not ( /abc/def/)
  3. It can have anything after contact

Examples:

nl/abc/contact --> allowed

nl/contact --> allowed

nl/abc/def/contact --> not allowed

nl/abc/contact/mno --> allowed

nl/abc/contactmno/ ---> not allowed

I tried writing one ("^nl(.?)/contact(.)$"), but it has a problem that it allows any number of slashes between nl and contact wheras I just want at max one slash in between

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I would use:

^nl(?:/[^/]+)?/contact(?:/[^/]+)*$

Demo

This pattern says to match:

^            from the start of the path
nl           starts with "nl"
(?:/[^/]+)?  any zero or one path parameter following
/contact     /contact
(?:/[^/]+)*  followed by zero or more other path parameters
$            end of the input
over 4 years ago · Santiago Trujillo 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!