Guest User

Untitled

a guest
Jul 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. var str = "///a/ab*/*/bc:dD:123a///'Ad/,.?/!//";
  2.  
  3. //if I use js replace with regex rule twice I get needed result
  4.  
  5. "///a/ab*/*/bc:dD:123a///'Ad,.?/!//"
  6. .replace(/[^0-9a-zA-Z()+-.,‘?/:]/g, "")
  7. .replace(/[^/+|/+$|/{2,}]/g, "");
  8.  
  9. //result
  10. "a/abbc:dD:123aAd/,.?"
  11.  
  12. **Is it possible to combine these rules into one regex rule?!**
  13.  
  14. //tried to combine these rules by '|' but get failure result
  15.  
  16. "///a/ab*/*/bc:dD:123a///'Ad/,.?/!//"
  17. .replace(/([^0-9a-zA-Z()+-.,‘?/:])|^/+|/+$|/{2,}/g, "")
  18. //result
  19. "a/ab//bc:dD:123aAd/,.?/"
  20.  
  21. 'a/ab*/*/bc'
  22.  
  23. 'a/ab//bc'
Add Comment
Please, Sign In to add comment