Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

63
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda