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

202
Views
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 answers
Answer question

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 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!