Reputation: 107
var st = "Dream Theater A Change of Seasons (EP) (1995)";
var searchTerm = st.replace("/[\s\W]+/g", "+");
gives
Dream Theater A Change of Seasons EP 1995
but I want to be
Dream+Theater+A+Change+of+Seasons+EP+1995+
Upvotes: 0
Views: 435
Reputation: 26179
You need:
var searchTerm = st.replace(/[\s\W]+/g, "+");
without quotes.
Upvotes: 2
Reputation: 120168
try
st.replace(/\s/g, "+");
which just replaces every whitespace char with a +
. Also note I removed the quotes around the regex -- you want a regex, not a string.
EDIT -- Just tried
st.replace(/[\s\W]+/g, "+"); // no quotes around the regex
and that gives you the +
on the end. So the real problem is you are passing a string when you want to pass an actual regex reference.
Upvotes: 1