与目录路径匹配的正则表达式,不包括文件路径 [英] Regex that matches directory path excluding filepath

查看:242
本文介绍了与目录路径匹配的正则表达式,不包括文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个需要IIS的正则表达式模式。基本上我希望它匹配任何目录路径,但拒绝文件路径。

I'm looking for a regex pattern that I need for IIS. Basically I want it to match any directory path but reject file paths. I've searched all over with little luck.

示例:匹配:/ directory / content / css /
匹配:/ directory / content / css
拒绝:/directory/content/css/main.css
拒绝:/directory/content/css/main.anything

Example: Match: /directory/content/css/ Match: /directory/content/css Reject: /directory/content/css/main.css Reject: /directory/content/css/main.anything

! - 由于反馈我已经做了一些修改(抱歉这是我第一次在论坛上) - !

!--Due to feedback I've made some changes (Apologies this is my first time on the forum)--!

到目前为止,我已经放在一起这种模式: ^(\ /.*)(.*)*[__.*]$
似乎开始确定接受任何以/但它仍然接受扩展。

So far I've put together this pattern: ^(\/.*)(.*)*[^.*]$ It appears to start out ok accepting anything starting with / but it still accepts extensions.

谢谢

推荐答案

正则表达式:

(?:\..*(?!\/))+

如果您有文件路径,则此正则表达式将匹配。

This regex will match if you got a file path..

Regex101

这篇关于与目录路径匹配的正则表达式,不包括文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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