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?
            Asked
            
        
        
            Active
            
        
            Viewed 41 times
        
    0
            
            
        - 
                    3Yes, 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 Answers
0
            
            
        You can combine both Regex formulas using logic operators inside (OR and AND). This answer will help you.
 
    
    
        Maor Roizman Gheiler
        
- 51
- 4
- 
                    not really, because you can't give 2 different results (to what to change it) – Flash Thunder Apr 22 '21 at 08:23