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

201
Views
Regex to mimic the js split function and extract the text

I have a text where I need to extract the community name The delimiter for spliting is " - "

Hence Iowa - Cedar Rapids - Meth-Wick Community must give result as Meth-Wick Community

if input is Iowa - Cedar Rapids - The Gardens of Cedar Rapids result must be The Gardens of Cedar Rapids

I have tried with

"Iowa - Cedar Rapids - The Gardens of Cedar Rapids".match(new RegExp(/([A-Z])\w{3}/gi))
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Try this one out for size:

console.log("Iowa - Cedar Rapids - The Gardens of Cedar Rapids".replace(/([\w\s]+)\s-\s([\w\s]+)\s-\s([\w\s]+)/i,'$3'));

about 4 years ago · Juan Pablo Isaza Report

0

You can do a negative lookahead to find the last occurrence of the delimiter as mentioned here https://stackoverflow.com/a/8374980/5417843 and then extract the community name from it.

input = "Iowa - Cedar Rapids - The Gardens of Cedar Rapids"
communityName = input.match(new RegExp('- (?:.(?!- ))+$')) // '- The Gardens of Cedar Rapids'
communityName[0].substring(2) // 'The Gardens of Cedar Rapids'
about 4 years ago · Juan Pablo Isaza Report

0

Here's a simple solution, used less regex as much as possible:

"Iowa - Cedar Rapids - Meth-Wick Community".split(/ - /g).slice(-1)[0]
"Iowa - Cedar Rapids - The Gardens of Cedar Rapids".split(/ - /g).slice(-1)[0]
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!