Use the OR operator (|):

var str = '#this #is__ __#a test###__';

console.log(
  str.replace(/#|_/g, '') // "this is a test"
)

You could also use a character class:

str.replace(/[#_]/g,'');

Fiddle

If you want to replace the hash with one thing and the underscore with another, then you will just have to chain

function allReplace(str, obj) {
  for (const x in obj) {
    str = str.replace(new RegExp(x, 'g'), obj[x]);
  }
  return str;
};


console.log(
  allReplace( 'abcd-abcd', { 'a': 'h', 'b': 'o' } ) // 'hocd-hocd'
);

Why not chain, though? I see nothing wrong with that.

Answer from tckmn on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-replace-multiple-characters-in-a-string
JavaScript - How to Replace Multiple Characters in a String? - GeeksforGeeks
July 23, 2025 - The replace() method with a regular expression is a simple and efficient way to replace multiple characters. ... The g flag ensures all occurrences are replaced.
Discussions

RegEx replace multiple characters
Anyone familiar with RegEx replace in one batch: Search: ä,ö,ü,© Replace: ae,oe,ue,c Thanks! More on forum.xojo.com
🌐 forum.xojo.com
1
0
January 20, 2023
javascript - Replace multiple characters in string - Salesforce Stack Exchange
I'm trying to replace the following This_is_awesome_news_ZZ__T and the end result I'm looking to have is this: This is awesome news Here is the javascript replace function: var str = ' More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
December 4, 2021
Wanting to replace any instance of multiple 'characters' with a single character.
Period has special meaning in RegEx. It means any character. You need to escape it with a backslash :) otherwise your RegEx looks correct. \.{2,} More on reddit.com
🌐 r/regex
4
3
December 16, 2021
How do I replace multiple strings in an array of Items
Dear Javascript legends of freeCodeCamp! I need your help! I have this code; let myArray = ['he123llo', 'cats', 'wor123ld', 'dogs']; const result = myArray.map(x =>x .replace('1', '') .replace('2', '') .replace('3', '') .replace('s', '') ); console.log(result); //[ 'hello', 'cat', 'world', ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
6
0
January 16, 2021
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › replace
String.prototype.replace() - JavaScript | MDN
The replace() method of String values returns a new string with one, some, or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function called for each match. If pattern is a string, only the first occurrence ...
🌐
Xojo Programming Forum
forum.xojo.com › general
RegEx replace multiple characters - General - Xojo Programming Forum
January 20, 2023 - Anyone familiar with RegEx replace in one batch: Search: ä,ö,ü,© Replace: ae,oe,ue,c Thanks!
🌐
Stack Abuse
stackabuse.com › bytes › how-to-replace-multiple-characters-in-a-string-with-javascript
How to Replace Multiple Characters in a String with JavaScript
September 21, 2023 - Replacing multiple types of characters in a string is a common task in JavaScript, and it's one that can be handled quite elegantly with the replace() method and regular expressions.
Find elsewhere
🌐
Reddit
reddit.com › r/regex › wanting to replace any instance of multiple 'characters' with a single character.
r/regex on Reddit: Wanting to replace any instance of multiple 'characters' with a single character.
December 16, 2021 -

I have a situation where there are multiple periods from string (i.e. Hello.......)

I am attempting to create a REPLACE to look for any instance where there are multiple periods, and replace with just one.

'Hello.......' would be 'Hello.'

text = 'Hello.......'
text = Regex.Replace(text, ".{2,}", ".")

But this doesnt seem to work..

Any assistance is appreciated.

🌐
MUI Stack
muhimasri.com › blogs › how-to-replace-multiple-words-and-characters-in-javascript
How to Replace Multiple Words and Characters in JavaScript
December 6, 2021 - Learn how to replace multiple words and characters using regular expressions and replaceAll function in JavaScript
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-replace-multiple-characters-in-string
Replace Multiple Characters in a String using JavaScript | bobbyhadz
str.replace(/[._-]/g, ' '). The first parameter the method takes is a regular expression that can match multiple characters.
🌐
Sentry
sentry.io › sentry answers › javascript › how do i replace all occurrences of a string in javascript?
How do I Replace all Occurrences of a String in JavaScript? | Sentry
The simplest and best way to replace multiple occurrences of a substring in a string is to use the replaceAll method. There are other methods you can use if you need to support older browsers.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
How do I replace multiple strings in an array of Items - Curriculum Help - The freeCodeCamp Forum
January 16, 2021 - I have this code; let myArray = ['he123llo', 'cats', 'wor123ld', 'dogs']; const result = myArray.map(x =>x .replace('1', '') .replace('2', '') .replace('3', '') .replace('s', '') ); console.log(result); //[ 'hello', 'cat', 'world', ...
🌐
FavTutor
favtutor.com › blogs › replace-multiple-characters-in-string-python
5 Ways to Replace Multiple Characters in String in Python
October 10, 2022 - Learn how to replace multiple characters in string in python. This includes replace() with Lists, Dictionaries, re module and translate() & maketrans().
🌐
SitePoint
sitepoint.com › blog › javascript › replace string characters in javascript
Replace String Characters in JavaScript — SitePoint
February 13, 2024 - Yes, you can use the replace() ... above code, “World” is removed from the string. To replace multiple different strings at once, you can chain replace() methods: let str = "Hello, World!...
🌐
LeetCode
leetcode.com › problems › string-compression
String Compression - LeetCode
Can you solve this real interview question? String Compression - Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating characters in chars: * If the group's length is 1, append the character to s. * Otherwise, append the character followed by the group's length.
🌐
RSWP Themes
rswpthemes.com › home › javascript tutorial › how to replace multiple characters in a string in javascript
How to Replace Multiple Characters in a String in JavaScript
January 14, 2024 - In this article, you’ll learn how to replace multiple characters in a string using JavaScript. By utilizing the replace() method and regular expressions, you can easily replace specific characters within a string.
🌐
W3Schools
w3schools.com › jsref › jsref_replace.asp
JavaScript String replace() Method
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
Make Community
community.make.com › questions
Multiple replace functions in one value - Questions - Make Community
September 22, 2022 - Hello together, is it possible to add multiple replace functions into one value? In the attached scenario I try to replace regular expressions with some other text. Unfortunately I have several expressions, each of whic…
🌐
TutorialsPoint
tutorialspoint.com › article › replace-multiple-instances-of-text-surrounded-by-specific-characters-in-javascript
Replace multiple instances of text surrounded by specific characters in JavaScript?
November 9, 2020 - var values = "My Name is #yourName# and I got #marks# in JavaScript subject"; const replacements = { yourName: "David Miller", marks: 97 }; var result = values.replace(/#([^#]+)#/g, (match, key) => replacements[key]); console.log(result);
🌐
IncludeHelp
includehelp.com › code-snippets › replace-multiple-characters-in-one-replace-call-using-javascript.aspx
Replace multiple characters in one replace call using JavaScript
July 24, 2022 - But this way only one character can be replaced in a single replace() method. For replacing multiple characters, one can use more replace() methods over and over again.