1

I do not know where my head is today, can somebody please explain to me - why I can get the hturl value by the request form and do the replace in the htstring? (I do this and it works - but only replaces one occurance of the (hturl) value.... The problem is that there is about 10 more occurances of the old value that I want to replace:

I am using Regex in conjunction with asp and javascript

<% 
htreplace = ""+Request.Form("1")+"";
hturl = Request.Form("thesite");
htstring = htreplace
htstring = htstring.replace(/,;~~~~/ig,';');
htstring = htstring.replace(hturl,'http://www.example.net');
%>

If I change the

htstring = htstring.replace(hturl,'http://www.example.net');

to

htstring = htstring.replace(/hturl/ig,'http://www.example.net');

or

htstring = htstring.replace("/"+hturl+"/"+ig,'http://www.example.net');

I cannot get the hturl value dynamically anymore ?

Anybody that can help please do! - I do not know where my head / logic is today! Thanks

1 Answer 1

4
var myregexp = new RegExp(hturl, "ig");

htstring = htstring.replace(myregexp, 'blah');
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Kaze! - Just learned something new and it works 100% zero issues!
3 years on, and still very helpful to the world ;-) Thanks so much... was tearing my hair out trying to work through this exact problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.