Solved

Remove querystring parameter regular expression

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now