Smudger
Smudger

Reputation: 10781

jquery replace string where complete string matches

I have a string.

var myexample="'product1','product61','product27','product15'";

I want to then replace product1 with blank

so I say: myexample=myexample.replace(product1, "");

This works, the problem is that is replaces product1 and the product 1 in product15 so my result is:

"'','product61','product27','5'";

I think what I need to do is get the length of the foun object to replace, if it is the same length as my search string then replace else ignore.

any advice welcome as always.

Thanks,

Upvotes: 0

Views: 41

Answers (1)

hsz
hsz

Reputation: 152226

Just try with:

myexample = myexample.replace("'product1'", "''");

Output:

"'','product61','product27','product15'"

Upvotes: 1

Related Questions