Hello guys,
I have a problem, i can't figure out a way to get out text between symbols.
site.com/hello-world/my-page-title/
i want to get my-page-title only? How? Thanks for your help,
Hello guys,
I have a problem, i can't figure out a way to get out text between symbols.
site.com/hello-world/my-page-title/
i want to get my-page-title only? How? Thanks for your help,
This regex will put "my-page-title" in the second group:
^([^/]*/){2}([^/]*)/$
If you always want the last group you can use:
^.*/([^/]*)/$
This regex always gives you the last URI segment in the first capturing group as long as the URI is terminated with a slash
.+/(.+)/
if the slash sometimes misses you can use
.+/(.+)/?
Well, i am not so good with regex, but title return null?
string url = /hello-world/my-page-text/
string title = Regex.Match(url, @"^*./([^/])/$").Groups[1].Value;
it did work, the * was the error in the regex code
You could use regex or String.Split
//Regex
string s = "site.com/hello-world/my-page-title/";
Match match = Regex.Match(s, "([^/]+)/$");
string matchedString = match.Groups[1].Value;
//Split
string[] sections = s.Split(new char[]{'/'},StringSplitOptions.RemoveEmptyEntries);
string lastSection = sections[sections.Length - 1];