There are times when you might want to paste the code snippet in to a webpage. Imagine if that code snippet contains the HTML tags and somehow you want to escape the markup code without the browser parsing it. An idea for this would be to use convert the angle brackets to its equivalent named entities like < and >.
You can use the combination of the string’s replace method and regular expression as shown below. Just use the global flag in the regular expression so that all the instances of the angle brackets are found and replaced with their named entities.
Enter your email address to subscribe to this blog and receive notifications of new posts by email.