Posted By

StrawMan on 06/11/11


Tagged

String


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Terion


String Manipulation - Regex Collection


 / Published in: JavaScript
 

  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  

You need to login to post a comment.