Re: How to extract variable and its value from URL

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Jozef,

You wouldn't even need a regular expression, you can just parse it apart
on the equals sign and the ampersand (but a regular expression would work
fine as well).

Pass the URL to the constructor of the Uri class, and then use the Query
property to get the query string. Drop the first character (it is always
the question mark), and the rest should be easy to parse. The only thing
you have to worry about at that point is the encoding which is a simple
matter of fixing).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Jozef Jarosciak" <joe@xxxxxxxxxxxxx> wrote in message
news:1121107806.318549.139710@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>I have url:
> www.site.com/index?a=1&b=2
> www.site.com/index?a=1
>
> and I need a regex or some solution to extract 'a' variable and its
> value.
>
> Any ideas?
> joe
>


.



Relevant Pages

  • RE: Check value is number only
    ... > more important than readability, and with extensive testing one can ... > dramatically reduce the risk of such a complicated regular expression from ... > While using a Parse() may be simpler and more readable, ... > invalid values are being dealt with, using the Regex method can be in the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Need help with regular expression to parse URLs
    ... I am having trouble figuring out how to write a regular expression to ... I am trying to parse the url ... Neil Aggarwal, 846-8957, www.JAMMConsulting.com ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ...
    (comp.lang.java.programmer)
  • Re: parse a file into text file
    ... I have to parse this text file. ... You might be able to write a regular expression that will satisfactorily break the data into pieces. ... If and when your employer finds out how careless you are with what is clearly sensitive information, you will be fortunate if you are simply removed from that project. ... Your best bet at the moment is to confess to your employer so that you can begin "damage control", including notification of the doctor and their patients to alert them to the fact that the data has been publicly released. ...
    (microsoft.public.dotnet.languages.csharp)
  • Need help with regular expression to parse URLs
    ... I am having trouble figuring out how to write a regular expression to ... I am trying to parse the url ... Pattern I apply to the group after I extract it from the main url? ...
    (comp.lang.java.programmer)
  • Request.QueryString in javascript and null parameters
    ... I'm writing Javascript code to parse out a query string. ... But it fails if it contains a value. ...
    (comp.lang.javascript)