javascript - Replace multiple characters in one replace call ...
stackoverflow.com › questions › 16576983Specify the /g (global) flag on the regular expression to replace all matches instead of just the first: string.replace(/_/g, ' ').replace(/#/g, '') To replace one character with one thing and a different character with something else, you can't really get around needing two separate calls to replace. You can abstract it into a function as Doorknob did, though I would probably have it take an object with old/new as key/value pairs instead of a flat array.
Replace multiple characters by one character with regex
stackoverflow.com › questions › 43446134Apr 17, 2017 · Your regex replaces single instance of any matched character with character that you specified i.e. #. You need to add modifier + to tell it that any number of consecutive matching characters (_,#) should be replaced instead of each character individually. + modifier means that 1 or more occurrences of specified pattern is matched in one go. You can read more about modifiers from this page:
C# regex replace multiple matches: A how-to guide – Wipfli
www.wipfli.com › c-regex-multiple-replacementsSep 24, 2019 · C# regex replace multiple matches. The Regex.Replace method has four overloads, but the basic syntax in .NET is Regex.Replace(string input, string pattern, string replacement). That didn't work for me because I needed the replacement value to vary, based on the pattern. For example, this simple replacement … Regex.Replace (input, "&", "&") … wasn't what I wanted, as that would mean repeating it for the other replacements.