944,161 Members | Top Members by Rank

Ad:
Jun 2nd, 2006
0

Regular Expression Help!

Expand Post »
I need to check if two parameter names exists in the url. If any of them do i need to replace the value of the parameter.

I can match the parameter name, but i am not sure how to replace the value. The two parameters/values would be at the end of the url.

what i have so far is below.

HTML and CSS Syntax (Toggle Plain Text)
  1. url = “http://www.daniweb.com?parm1=value&parm2=value&parm3=value&parm4=value
  2.  
  3. // can i combine these some how?
  4. var parm3RegExp = /parm3=/;
  5. var parm4RegExp = /parm4=/;
  6.  
  7. // finds parm3. Now how can i replace the value?
  8. url = parm3RegExp.exec(url)

I was thinking about something like below. but i want to replace the parameter value and not the name
HTML and CSS Syntax (Toggle Plain Text)
  1. var url = url.replace(/parm3=/, "");
Similar Threads
Reputation Points: 13
Solved Threads: 2
Junior Poster in Training
Sailor_Jerry is offline Offline
88 posts
since Aug 2005
Jun 2nd, 2006
0

Re: Regular Expression Help!

Got this to work.
I will just remove the parameters and the values if they are present in the url. Then run the logic to create and add the paramters and there values to the url, if they are needed.

HTML and CSS Syntax (Toggle Plain Text)
  1. url = “http://www.daniweb.com?parm1=value&parm2=value&parm3=value&parm4=value
  2. var urlParm3loc = url.search(/&parm3=/);
  3. var urlParm4loc = url.search(/&parm4=/);
  4.  
  5. if(urlParm3loc > 0 || urlParm4loc > 0)
  6. {
  7. var startIndex = urlParm3loc > urlParm4loc ? urlParm4loc : urlParm3loc ;
  8. url = url.replace(url.substring(startIndex,url.length),"");
  9. }
Reputation Points: 13
Solved Threads: 2
Junior Poster in Training
Sailor_Jerry is offline Offline
88 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: Image Swap help
Next Thread in HTML and CSS Forum Timeline: Rotating flash movies per page load





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC