Solved

Remove querystring parameter regular expression

Posted on 2006-11-24
3
517 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
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 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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.…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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