Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Remove querystring parameter regular expression

Posted on 2006-11-24
3
Medium Priority
?
535 Views
Last Modified: 2008-02-01
I need a single regular expression that is capable of removing a given parameter from a url.

For example:
    test.asp?id=34                                        > becomes >            test.asp
    test.asp?id=34&other=test                       > becomes >            test.asp?other=test
    test.asp?other=test&id=34                       > becomes >            test.asp?other=test
    test.asp?other=test&id=34&test=34          > becomes >            test.asp?other=test&test=34

Thanks
ant
0
Comment
Question by:CVSmarc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18012866
while( <DATA> ){
  s/([&?])id=[^&]*(&)?/$2&&$1/e;
  print
}
__DATA__
 test.asp?id=34              
  test.asp?id=34&other=test          
  test.asp?other=test&id=34                      
  test.asp?other=test&id=34&test=34
0
 
LVL 29

Accepted Solution

by:
Nightman earned 2000 total points
ID: 18012902
This will do it, but it isn't all that pretty

RegEx r =new Regex(@"(id=)[0-9]+(&)|(id=)[0-9]+|(&id=)[0-9]+|(\?id=)[0-9]+$");
0
 
LVL 4

Author Comment

by:CVSmarc
ID: 18013319
Thanks for this Nightman
I know that it isn't all that pretty but it will do for what i need it for.
ant
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question