regex - C# regular expressions for URL query strings -


i got following scenario:

i affiliate network url , need append appropriate url parameter tracking purposes (subid).

the actual problem: in cases 1 affiliate network supports different query string formats. example:

1) http:/ /impde.sampleaffiliate.com/imp?pop(over)g(xxxxx)a(xxx)subid(subidvalue) 

or

2) http:/ /clkde.sampleaffiliate.com/click?p=xxx&a=xxx&g=xxx&subid=subidvalue 

the recognition of affiliate network pretty simple [url.contains("sampleaffiliate")], query string format, i'm using regular expressions:

//query string parameter values in brackets, e.g. ?a(12312)b(12343432)c(4242) regex parametersinbrackets = new regex(@"^[\?]{1}\w+(\(.*\))+$"); //query string parameter values separated ampersands , equal signs, e.g. ?a=12312&b=12343432&c=4242 regex parameterswithampersand = new regex(@"^[\?]{1}.+(\&\w+\=.+)+$"); 

those work fine "normal cases".

but here comes additional difficulty - @ following url:

http:/ /pdt.sampleaffiliate.com/click?a(aaa)p(bbb)prod(ccc)ttid(ddd)url(http:/ /www.example.com/item.asp?param1=eee&param2=fff&param3=ggg) 

in case use name(value)name(value) notation in query string, value last parameter ("url"), there url in &name=value&name=value notation, makes hard regex see, of both 1 supposed used...

my current regular expressions both return "true" on ismatch(uri.query) last example.

any ideas how fix this?

thanks in advance!

the "difficult link" getting not url encoded, suspect built in parsequerystring won't work (and assume unfortunately out of control).

you can use following regex parse pieces:

^[\?]{1}(\w+\([^\)]+\))+$  a(aaa) p(bbb) prod(ccc) ttid(ddd) url(http://www.example.com/item.asp?param1=eee&param2=fff&param3=ggg) 

use regex first; if returns match use it. if fails, use build in parsequerystring.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -