Parse URL parameter regular: (? <=\?| &) [\w\={},: ' ""]* (? <=[^#])
The project will be used for a long time or not. Finally give up using split split method to resolve the discovery of the outdated
Public StaticNameValueCollection QueryString (stringpath) { if(string. IsNullOrEmpty (Path)) {return NULL; } varArr=path. Split (New Char[] {'?'}, Stringsplitoptions.removeemptyentries); if(arr.) Length! =2) { return NULL; } varValues = arr[1]; Arr= values. Split (New Char[] {'&'}, Stringsplitoptions.removeemptyentries); if(arr = =NULL)return NULL; string[] itemvalues; NameValueCollection Nvcs=NewNameValueCollection (); foreach(varItemincharr) {Itemvalues= Item. Split (New Char[] {'='}, Stringsplitoptions.removeemptyentries); if(Itemvalues = =NULL|| Itemvalues. Length = =0)Continue; Nvcs. ADD (itemvalues[0], itemvalues. Length <=1?string. empty:itemvalues[1]); } returnNvcs; }
And then go see the regular document. Modified version
Public StaticNameValueCollection QueryString (stringpath) { if(string. IsNullOrEmpty (Path)) {return NULL; } varm = regex.matches (Path,@"(? <=\?| &) [\w\={},: ' ""]* (? <=[^#])", Regexoptions.none); if(M.count <=0) { return NULL; } NameValueCollection Nvcs=NewNameValueCollection (); string[] Itemvalues =NULL; for(inti =0; i < M.count; i++) {itemvalues= M[i]. Value.split (New Char[] {'='}, Stringsplitoptions.removeemptyentries); if(Itemvalues = =NULL|| Itemvalues. Length = =0)Continue; Nvcs. ADD (itemvalues[0], itemvalues. Length <=1?string. empty:itemvalues[1]); } returnNvcs; }
Regular expression parsing URL parameters