<script type="text/javascript">
var currstr = "?distance=10&city=Boston&criteria=shoes&size=10";
var selcity = "California"; //This can come from a drop down
var pat = new RegExp([NEEDPATTERN],"gi");
currstr.replace(pat,selcity);
</script>
I need some help replacing city=Boston in currstr with a value user selects from
drop down, right now I have hardcoded value in var selcity. I have placed a [NEEDPATTERN] marker for pattern that can be used to achieve this.
Can someone help me with this pattern?
Do you want to replace “Boston” specifically, or do you need to just replace the
Xincity=X?For boston, you can just use simple substitution…
currstr.replace('Boston', selcity)For replacing
X, you can do:currstr.replace(/city=([^&]+)/, selcity);