Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex replace not replacing value

My regex code is not operation.
Input string:

let question = "THIS IS MALICIOUS <h1>OOGA</h1>"

Faulty Code:

question = question.replace(/^[a-zA-Z0-9?!.]+$/g, "");

Output string:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"THIS IS MALICIOUS </h1>OOGA</h1>"

Correct / Expected Output string:

"THIS IS MALICIOUS OOGA"

>Solution :

please try with following code

let question = "THIS IS MALICIOUS &lt;h1&gt;&OOGA&lt;/h1&gt;"
question  = question .replace(/<[^>]*>/g, "")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading