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

137
Views
Regex in Javascript to find incomplete items that begin and end with brackets

I'm trying to use regex to find any incomplete things that begin with {{.

I've tried to check for any places in the string that begin with {{ and have a-Z after it but haven't been ended (}}). What I'm trying always returns null.

string = 'Hello {{name}}, you are {{a';
console.log(string.match(/^({{)?[a-z]:[A-Z]$/g));

My expected output would be {{a in this case because {{name}} is complete. Any help really appreciated.

The only things it will have between it is . ie: {{name.forename}} {{name.lastname}}

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

0

You can use the "best regex trick ever", in this case, match all word char chunks between double curly braces or match and capture any {{ followed with zero or more word chars:

Array.from(text.matchAll(/{{\w+(?:\.\w+)*}}|({{(?:\w+(?:\.\w+)*)?)/g), x => x[1]).filter(Boolean)

Here,

  • {{\w+(?:\.\w+)*}} - {{, one or more word chars, zero or more sequences of a . and one or more word chars, }}
  • | - or
  • ({{(?:\w+(?:\.\w+)*)?) - Group 1: {{ and an optional occurrence of one or more word chars and zero or more sequences of a . and one or more word chars.
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!