using regex with replace to replace all instances of something in a string

so you have a string and you want to replace a recurring character, use this to do it:

String Example: var string = "a-string-with-dashes.txt";

var string = "a-string-with-dashes.txt";
string = string.replace(/-/g , " ");

string should now = a string with dashes.txt

String Test

You can edit the following strings to test or just run it to see the result.

String to Replace:


Run Replace


Other Items in js
Page Views

This page has been viewed 43 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.