Wednesday, 15 May 2013

c# - How to extract the filename from a request url using Regex in ASP.NET -



c# - How to extract the filename from a request url using Regex in ASP.NET -

i need extract filename + extension request having .aspx extension within request url. ex. if requested url - http://www.abcd.com/index.aspx?a=1&b=2 should homecoming index.aspx. if requested url http://abcd.com/products/pages/page1 should homecoming empty.if requested url http://abcd.com/images/img1.gif should homecoming empty.

edit: if there aspx anywhere else in url might pose actual problem. escaping . , looking . within url, , getting first match might solve problem hostname's dont have .aspx in them.

try this:

match filenamematch = regex.match("url", @"\w+\.aspx"); string filename = filenamematch.value;

c# asp.net regex

No comments:

Post a Comment