Reputation: 1
I am new to the asp.net c# development i need to get "test.aspx" part only from this string "/test1/Pages/Request/test.aspx?id=-1" .Please help me if some one know better way to do that ,i check some regular expression methods but still i haven't correct solution.
Thanks
Upvotes: 0
Views: 677
Reputation: 2461
Assuming your pages will all be .aspx
:
(?<=/)\w+.aspx(?=\?)
In C# use:
@"(?<=/)\w+.aspx(?=\?)"
---Edit---
If you want to catch more characters, you can modify the bold part of the expression below:
(?<=/)[\w\.]+.aspx(?=\?)
The second regex will also match dots in the part preceding .aspx
.
Upvotes: 0
Reputation: 67968
([a-zA-Z.]+)(?=\?)
You can use this.Just grab the first group.See demo.
http://regex101.com/r/jT3pG3/2
Upvotes: 0
Reputation: 14460
Have a look at Uri.AbsolutePath
So can do
Path.GetFileName(Request.Url.AbsolutePath)
Upvotes: 1
Reputation: 4706
string str = "/test1/Pages/Request/test.aspx?id=-1";
string page = str.Substring(str.LastIndexOf('/')+1, str.IndexOf('?')-str.LastIndexOf('/')-1);
Upvotes: 0