Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

64
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda