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
Solved

Remove querystring parameter regular expression

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 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