This article illustrates how JS uses regular expressions to filter multiple words and replaces them with asterisks of the same length. Share it for your reference, as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>regular filtering</title></head><body><script type="text/javascript">var text = "Filter sensitive words and uncivilized terms";var re = /Sensitive words | Civilization/gi;var output = text.replace(re, function(sMatch){ return sMatch.replace(/./g,"*");});document.write(output);</script></body></html>The operation results are shown in the figure below:
PS: Here are two very convenient regular expression tools for your reference:
JavaScript regular expression online testing tool:
http://tools.VeVB.COM/regex/javascript
Regular expression online generation tool:
http://tools.VeVB.COM/regex/create_reg
For more information about JavaScript related content, please check out the topics of this site: "JavaScript Regular Expression Skills", "Summary of JavaScript Replacement Operation Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Data Structure and Algorithm Skills", "Summary of JavaScript traversal algorithms and techniques", "Summary of json operation techniques in JavaScript", "Summary of JavaScript Errors and Debugging Skills" and "Summary of JavaScript Mathematical Operation Usage"
I hope this article will be helpful to everyone's JavaScript programming.