Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  132] [ 7]  / answers: 1 / hits: 54539  / 13 Years ago, thu, march 24, 2011, 12:00:00

I have a string which is something like this :



a_href= www.google.com/test_ref=abc;


I need to search for test_ref=abc in thisabove strinng and replace it with new value



var updated_test_ref = xyz;

a_href =www.google.com/test_ref=updated_test_ref


i.e



www.google.com/test_ref=xyz.


How can we do this ?



EDIT:



test_ref value can be a URL link in itself something like http://google.com?param1=test1&param2=test2. I need to capture complete value not till first &.


More From » search

 Answers
86
a_href = a_href.replace(/(test_ref=)[^&]+/, '$1' + updated_test_ref);

[#93106] Tuesday, March 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yulissamirandah

Total Points: 493
Total Questions: 115
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;