Regular Expression question

  • Thread starter Thread starter holysmokes99
  • Start date Start date
You coule use String.LastIndexOf() and String.Substring(), which is much less
expensive than a regex.

string url = "http://hello.com/foo/bar/lalala";

int index = url.LastIndexOf('/');

if (index > -1)
{
return url.Substring( index );
}


HTH
 
(e-mail address removed) explained on 9-1-2008 :
I am trying to grab the last bunch of text after the last forward
slash (/) in a url string. For example, I want to match "want" from
the string "http://www.hello.com/whatever/you/want". Using "/(.+)$" as
my regular expression yields "/www.hello.com/whatever/you/want", which
of course is not what I want. Any one able to help me out?

Thanks,
Marcus

If you *really* want a regex, use "/([^/]+)$", that is: replace the "."
(meaning "any character") with "[^/]" (meaning "any char but /").

Hans Kesting
 
KH and Hans, Thanks for your help!

Marcus

(e-mail address removed) explained on 9-1-2008 :
I am trying to grab the last bunch of text after the last forward
slash (/) in a url string. For example, I want to match "want" from
the string "http://www.hello.com/whatever/you/want". Using "/(.+)$" as
my regular expression yields "/www.hello.com/whatever/you/want", which
of course is not what I want. Any one able to help me out?
Thanks,
Marcus

If you *really* want a regex, use "/([^/]+)$", that is: replace the "."
(meaning "any character") with "[^/]" (meaning "any char but /").

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top