0

I have two different Regex formuals, one for replacing spaces, commas, and periods with an underscore: /[ ,.]/g,"_" and another one removing symbols /[!@#$%^&*]/g,"". Is there a way to combined these two together into one expression?

  • 3
    Yes, string.replace can take in a handler function that you can use to differentiatee the 2 cases. But it'd be cleaner to just invoke.replace twice. – junvar Apr 21 '21 at 22:02
  • Thank you, I have .replace twice and its working great. Is that the cleanest way to use 2 different cases? –  Apr 21 '21 at 22:15
  • Yes, when the replace-with string is different (i.e. '_' v ''), 2 replaces is appropriate. – junvar Apr 21 '21 at 22:29

1 Answers1

0

You can combine both Regex formulas using logic operators inside (OR and AND). This answer will help you.