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

207
Visualizações
Javascript Regular expression to match text between a colon sign and sentences ended by a dot

Suppose I have a text like this:

This is the title: \ titles always have a colon
This is a regular sentence.
A sentence always ends with a period.
A sentence can
span multiple lines.
A sentence can contain numbers like 123.
The phrase can also contain "text enclosed in double quotes" or 'text enclosed in single quotes'.
Other symbols that may appear in sentences are
the comma ,
the semicolon ;
the dollar sign $
parentheses ( )
the plus sign + the minus sign - and the square brackets[ ].

This is an isolated phrase that the regular expression should not match.

How could I create a regex in javascript to match the text between the first colon* and the last full stop after brackets[ ]? (assuming there will be no other colon, if there are any, they will be enclosed in double quotes)

I've tried using :.* but it maches all lines.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Using the s flag, the following regex captures everything after the colon till the double linebreak.

/(?<=:).*?(?=(?:\r?\n)+[^\n]*$)/sg

Test on regex101 here

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