使用正则表达式URL匹配的文件夹名称 [英] Match folder name from url using regex

查看:129
本文介绍了使用正则表达式URL匹配的文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只匹配文件夹名称,一个文件在,

I want to match just the folder name that a file is in,

例如:

PIC / 2009年

PIC / 2009 / 01 /cat02.jpg

eg:
pic/2009/cat01.jpg
pic/2009/01/cat02.jpg

我只想匹配什么我把大胆的。

I want to just match what I put in bold.

到目前为止,我有这样的:

[^/]*/

将匹配,

PIC / 2009 / cat01.jpg

Which will match,
pic/2009/cat01.jpg

任何想法?

推荐答案

如果不使用常规的前pression:

Without using a regular expression:

FILE_NAME="pic/2009/cat01.jpg"
basename $(dirname $FILE_NAME)

目录名获取路径的目录部分,基本名打印的最后部分。

dirname gets the directory part of the path, basename prints the last part.

这篇关于使用正则表达式URL匹配的文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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