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

151
Views
Replace and transform text using regex

I have a text with a pattern. And it needs to be transformed to a text that is more readable to the user.

//Rawtext => transformed text
@[John](john@gmail.com), how are you? => @John, how are you?
Good morning @[Doe](doe@gmail.com) => Good morning @Doe.

Any help is deeply appreciated. Thanks in advance.

Note: related to the react-mentions package for reactjs

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

0

This might work.

const regex = /@\[([^\]]+)\]\([^\)]+\)/g;

console.log('@[John](john@gmail.com), how are you?'.replace(regex, '@$1'));
console.log('Good morning @[Doe](doe@gmail.com)'.replace(regex, '@$1'));

about 4 years ago · Juan Pablo Isaza Report

0

Here is one way to do it:

const re = /\[(\w+)\]|\(.+\)/g

const a = '@[John](john@gmail.com), how are you?'
const b = 'Good morning @[Doe](doe@gmail.com)'

const result_A = a.replace(re, '$1')
const result_B = b.replace(re, '$1')

console.log(result_A)
console.log(result_B)

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!