Reputation: 275
Having trouble converting a simple regex to a regex object... using jquery replace.
var st = "saturate(0.2)"
// this is working
alert(st.replace(/saturate\(.*?\)/, "saturate(0.5)"))
// so why is this not working exactly the same?
var st = "saturate(0.2)"
var regex = new RegExp("saturate\(.*?\)", "")
alert(st.replace(regex, "saturate(0.5)"))
Upvotes: 1
Views: 44
Reputation: 149040
You need to escape the \
characters inside a string literal:
var regex = new RegExp("saturate\\(.*?\\)", "")
Upvotes: 4