从最后2个"/"中提取字符串在路上 [英] Extract string from last 2 "/" on a path

查看:95
本文介绍了从最后2个"/"中提取字符串在路上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试提取两个"/"之间的最后一个字符串

I'm trying to extract the last string between two "/"

例如: 对于此字符串: https://stackoverflow.com/questions/ask

for example: for this string: https://stackoverflow.com/questions/ask

我想返回问题"

但是,对于此字符串 从单元格中提取最后一个子串

However, for this string Extract the last substring from a cell

我要返回"6133287"

I want to return "6133287"

它必须始终是最后两个"/"之间的字符串

It has to always be the string in between the last two "/"

我正在使用在此论坛中找到的一些MID函数,但是它们正在处理字符串开头的内容.不一定适用于具有不同长度的字符串.

I was working with some MID functions I found in this forum, but they were working for things at the beginning of the string. Not necessarily for strings with different lengths.

谢谢, J

推荐答案

$re = "/\\/([^\\/]+)(?=\\/[^\\/]+\\/?$)/"; 
$str = "https://stackoverflow.com/questions/ask"; 

preg_match($re, $str, $matches);

这篇关于从最后2个"/"中提取字符串在路上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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