正则表达式模式匹配字符串的结尾 [英] regex pattern to match the end of a string

查看:275
本文介绍了正则表达式模式匹配字符串的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我正则表达式模式匹配字符串中最后一个/右边的所有内容。

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

例如,str =red / white / blue;

For example, str="red/white/blue";

我想匹配蓝色因为它是所有在最后一行的右边/\".

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

非常感谢!

推荐答案

在Perl中:

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

在Javascript中:

In Javascript:

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

这篇关于正则表达式模式匹配字符串的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆