Created
February 9, 2016 10:51
-
-
Save srkama/a86d729a67cfaca62d1d to your computer and use it in GitHub Desktop.
a global replace using regex in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function convert(str) { | |
| // :) | |
| htmlEntities = [ | |
| ['&', '&'], | |
| ['<','<'], | |
| ['>', '>'], | |
| ['\'','''], | |
| ['"','"'], | |
| ]; | |
| myRegEx = /[^a-z\d]/i; | |
| for (i=0;i<htmlEntities.length;i++) { | |
| str = str.replace(new RegExp(htmlEntities[i][0], 'g'), htmlEntities[i][1]); | |
| } | |
| return str; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment