Regular Expression Help!

Reply

Join Date: Aug 2005
Posts: 75
Reputation: Sailor_Jerry is an unknown quantity at this point 
Solved Threads: 2
Sailor_Jerry's Avatar
Sailor_Jerry Sailor_Jerry is offline Offline
Junior Poster in Training

Regular Expression Help!

 
0
  #1
Jun 2nd, 2006
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=/, "");
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 75
Reputation: Sailor_Jerry is an unknown quantity at this point 
Solved Threads: 2
Sailor_Jerry's Avatar
Sailor_Jerry Sailor_Jerry is offline Offline
Junior Poster in Training

Re: Regular Expression Help!

 
0
  #2
Jun 2nd, 2006
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. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC