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

62
Views
Regex get string before ending with second occurance

The string can be http://url.com/scripts.js:129:1 or http://url.com/scripts.js:129 but I always want http://url.com/scripts.js:129.

Here is what I tried, but it keeps changing array index. 'http://url.com/scripts.js:129:1'.match(/(.+)(\:\d+(?!\:\d+)?)$/);

Help me, why my regex is not working properly.

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

0

If the point is to get till the first : + number and omit the rest, you can use

^(.+?:\d+)(?::\d+)*$
^.+?:\d+

See this regex demo. ^.+?:\d+ is preferable if you do not need to match the entire string and capture both parts into groups.

Details:

  • ^ - start of string
  • (.+?:\d+) - Group 1 capturing any one or more chars other than line break chars as few as possible and then a : and one or more digits, and then
  • (?::\d+)* - zero or more sequences of : and one or more digits
  • $ - end of string.
about 4 years ago · Juan Pablo Isaza Report

0

Try the following pattern:

/:(\d+)(?::\d+)?$/

It assumes that there may be another colon-number pair, but it's optional.

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!