I'm new at regular expressions and wonder how to phrase one that collects everything after the last /
.
I'm extracting an ID used by Google's GData.
my example string is
http://spreadsheets.google.com/feeds/spreadsheets/p1f3JYcCu_cb0i0JYuCu123
Where the ID is: p1f3JYcCu_cb0i0JYuCu123
Oh and I'm using PHP.
This matches at least one of (anything not a slash) followed by end of the string:
Notes:
+
(instead of*
) so that if the last character is a slash it fails to match (rather than matching empty string).But, most likely a faster and simpler solution is to use your language's built-in string list processing functionality - i.e.
ListLast( Text , '/' )
or equivalent function.For PHP, the closest function is strrchr which works like this:
This includes the slash in the results - as per Teddy's comment below, you can remove the slash with substr: