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

94
Views
JavaScript regex - replacing \btext with html tag

const obj = {text: "The\bNew stylish \biPhone"}

I would like to replace all words in the above object that starts with '\b' followed by a single word with bold html tag with the identified word in the tag

i.e. text: "The\bNew stylish \biPhone" should be text: "The <b>New</b> stylish <b>iPhone</b>"

Thanks

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You can capture \\b(\S+) and replace it with < b>$1< /b >.

Here \\b matches literal \b and (\S+) matches any word or text in general and gets captured in group1 which you can use to replace the matched text with bold tags.

const s = 'The \\bNew stylish \\biPhone';
console.log(s.replace(/\\b(\S+)/g, '<b>$1</b>'))

Just in case you want to limit any character set matching the world, change \S+ to something like \w or [a-zA-Z] and so on.

about 4 years ago · Santiago Gelvez 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!