String Manipulation - Regex Collection


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //Remove every second comma only and replace with spaces and double colon.
  2. function remComma(str) {
  3. return str = str.replace(/(,[^,]*),/g, '$1 :: ');
  4. }
  5. //Remove all commas outside of html markup only.
  6. function remAllComma(str) {
  7. return str = str.replace(/,(?!([^<]+)?>)/g, '');
  8. }
  9. //Remove all commas, everywhere.
  10. function remTotalComma(str) {
  11. return str = str.replace(/,/g, '');
  12. }
  13. //Discard all square brackets from string.
  14. function remSquareBrackets(str) {
  15. return str = str.replace(/\[|\]/g, '');
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.