?
Solved

Remove querystring parameter regular expression

Posted on 2006-11-24
3
Medium Priority
?
522 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

770 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