Skip to content
Advertisement

How to replace Unicode characters in the following scenario using javascript?

How to replace Unicode characters in the following scenario using javascript? Using javascript I want to replace Unicode characters with a wrapper according to their style. If possible include a range of Unicode characters([a-z]) in regex for styles other than regular.

  • input = abc๐‘ข๐‘ฃ๐‘ค๐‘ฅ๐š๐›๐œ๐๐’‡๐’ˆ๐’‰๐’Š
  • expected ouput = <span class="regular>abc</span><i> ๐‘ข๐‘ฃ๐‘ค๐‘ฅ</i><b>๐š๐›๐œ๐</b><b><i>๐’‡๐’ˆ๐’‰๐’Š</i></b>

JavaScript

Advertisement

Answer

I think itโ€™s just a matter of finding the Unicode ranges you want to replace, and normalizing (decomposing) the string:

JavaScript
Advertisement