I need some help with the regex as i am writing a new rule in the helicon.
the sample url will have file name and a query string parameter i want to match on both
www.testwebsite.com/hello.aspx?filename=/test.asp&employeeid=2100&age=20 开发者_JS百科
in the above url i want to check if it is hello.aspx and has query string filename=/test.asp
filename can be anywhere in the querystring.
i want to break the above url into some other page
mynewpage.aspx $2$3 etc///
i wrote the following url but its not working , it matching pattern for all like sample1.aspx or any file name
(.*)(\/hello.aspx\?+)(.*)(filename=\/test\.asp)(.*)
any help will be appreciated
What you need are non capturing groups:
(?:.*)(\/hello.aspx\?+)(?:.*)(filename=\/test\.asp)(?:.*)
["www.testwebsite.com/hello.aspx?filename=/test.asp&employeeid=2100&age=20", "/hello.aspx?", "filename=/test.asp"]
(?:.*)(\/hello.aspx\?+)(?:.*)(filename=\/test\.asp)(.*)
["www.testwebsite.com/hello.aspx?filename=/test.asp&employeeid=2100&age=20", "/hello.aspx?", "filename=/test.asp", "&employeeid=2100&age=20"]
If you want to get all the parameters separately from the query string you can do it like this:
string queryString = (new Uri("...")).Query;
NameValueCollection parameters = HttpUtility.ParseQueryString(queryString);
parameters.Get("filename");
parameters.Get("employeeid");
parameters.Get("age");
精彩评论