Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  143] [ 7]  / answers: 1 / hits: 131447  / 13 Years ago, mon, june 27, 2011, 12:00:00

Can someone tell me the regex pattern to match everything to the right of the last / in a string.



For example, str=red/white/blue;



I'd like to match blue because it is everything to the right of the last /.



Many thanks!


More From » regex

 Answers
5

Use the $ metacharacter to match the end of a string.



In Perl, this looks like:



my $str = 'red/white/blue';
my($last_match) = $str =~ m/.*/(.*)$/;


Written in JavaScript, this looks like:



var str = 'red/white/blue'.match(/.*/(.*)$/);

[#91482] Friday, June 24, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alejandro

Total Points: 231
Total Questions: 102
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
alejandro questions
Mon, Jul 18, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
Thu, Sep 10, 20, 00:00, 4 Years ago
;