-3

So I have a string in which there are words like this <00asjdask> for example

 var str="hello <00dansld> this is ur system <00aldjs> and you are <00jdak>" 

So I have to make the words inside brackets <> in bold and print it inside an html page so in html page it would look like

hello < <b>00dansld<b> > this is ur system < <b> 00aldjs <b> > . 

how can I do it ? I thought of using regex but I don't know how ?

Liam
  • 27,717
  • 28
  • 128
  • 190
  • Are string in <> fixed ? – Prathmesh Kadam Feb 27 '19 at 13:24
  • 1
    [Have you made any attempt to solve this yourself? Can you share what you've tried?](http://idownvotedbecau.se/noattempt/) – Liam Feb 27 '19 at 13:25
  • Please read [How do I format my code blocks?](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks). I've attempted to translate your code as best I can, it would of been much better if you'd done this yourself. – Liam Feb 27 '19 at 13:26
  • Possible duplicate of [how to replace all occurrence of string between two symbols?](https://stackoverflow.com/questions/25606731/how-to-replace-all-occurrence-of-string-between-two-symbols) – Kaddath Feb 27 '19 at 13:26

1 Answers1

0

You could use the Regex <(\w+)> and replace every occurence with &lt;<strong>$1</strong>&gt;:

const text = "hello <00dansld> this is ur system <00aldjs>";

const replaced = text.replace(/<(\w+)>/g,'&lt;<strong>$1</strong>&gt;');

document.body.innerHTML = replaced;
Zenoo
  • 12,670
  • 4
  • 45
  • 69