Home > Web Front-end > JS Tutorial > body text

Replace parentheses, angle brackets, etc. using JS regular expressions

高洛峰
Release: 2017-01-14 09:32:31
Original
1899 people have browsed it

As shown below:

function toTxt(str) { 
  var RexStr = /\<|\>|\"|\&#39;|\&/g 
  str = str.replace(RexStr, function(MatchStr) { 
    switch (MatchStr) { 
    case "<": 
      return "<"; 
      break; 
    case ">": 
      return ">"; 
      break; 
    case "\"": 
      return """; 
      break; 
    case "&#39;": 
      return "&#39;"; 
      break; 
    case "&": 
      return "&"; 
      break; 
    default: 
      break; 
    } 
  }) 
  return str; 
}
Copy after login

The above article uses JS regular expressions to replace brackets, angle brackets, etc. This is all the content shared by the editor. I hope it can give you a For reference, I also hope that everyone will support the PHP Chinese website.

For more related articles on using JS regular expressions to replace brackets, angle brackets and other related articles, please pay attention to the PHP Chinese website!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!