0

I'm trying to replace text inside of parenthases with the same text surrounded by <span class="bold">my text between parenthases</span>

text.replace(/\[([^\][]+)]/g, "<span class='font-weight-bold underline'>$1</span>")

so If I have this is my [name] It replaces it to this is my <span class="bold">name</span>

I need something similar for parentheses.

How can I replace text globally between parentheses? It's not a simple as I thought it would be.

Train
  • 3,420
  • 2
  • 29
  • 59
  • Possible duplicate of [RegEx match open tags except XHTML self-contained tags](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Isaac Dec 07 '17 at 22:39
  • How is that a duplicate? I'm not parsing HTML – Train Dec 07 '17 at 22:42

2 Answers2

2

Replace your regex with text.replace(/\(([^\][]+)\) */g, "<span class='font-weight-bold underline'>$1</span>");

2hTu2
  • 378
  • 4
  • 19
0

Try this...

text.replace(/ *\([^)]*\) */g, "<span class='font-weight-bold underline'>$1</span>");
curv
  • 3,796
  • 4
  • 33
  • 48
  • $1 should represent the text in the parenthases. In this case it replaces the text with $1. – Train Dec 07 '17 at 22:44