Using regex in javascript to cut substring

advertisements

There are some strings

"string numbe1 fdsf gfdgfdgf (value1)"
"string numbe2 fdsf gfdgfdgf (value2)"
"string numbe3 fdsf gfdgfdgf (value3)"
"string numbe5 fdsf gfdgfdgf (value1)"
"string numbe5 fdsf gfdgfdgf (value2)"

(valueN) can be either (value1) or (value2) or (value3). I need to cut it from the original string by using javascript regex. So the newString must be kind of string numbe1 fdsf gfdgfdgf

Here is what I did (and which is not working as I want)

var newString = originalString.replace(/(value1)|(value2)|(value3)/g,"") ;

It returns "1 ()".

How can I solve it?


you need to escape the parenthesis, and you have an extra . right before replace

"string numbe5 fdsf gfdgfdgf (value2)".replace(/\(value[1-3]\)/, '')