首页前端开发其他前端知识一个正则表达式的看法(?:)

一个正则表达式的看法(?:)

时间2024-02-01 16:34:03发布访客分类其他前端知识浏览508
导读:收集整理的这篇文章主要介绍了一个正则表达式的看法(?:),觉得挺不错的,现在分享给大家,也给大家做个参考。 原正则的出现是为了实现apache上传目录无执行权限,不过大家知道在 wind...
收集整理的这篇文章主要介绍了一个正则表达式的看法(?:),觉得挺不错的,现在分享给大家,也给大家做个参考。 原正则的出现是为了实现apache上传目录无执行权限,不过大家知道在 windows下对于文件名是不区分大小写的,但在*unx下就不同了,其中st0p.php和st0p.Php是两个不同的文件,所以此正则(?i:.php)出现
复制代码 代码如下:
Directory "/VAR/www/upload">
FilESMatch "(?i:.php)">
Order Allow,Deny
Deny From all
/FilesMatch>
/Directory>

kindle说是参考http://perldoc.perl.org/perlre.html#Extended-Patterns的内容进行写的,具体的内容大家自己看,我们说一下关于此表达式的部分..

我们找到?:相关的部分,其用法有两种(?:pattern)和(?imsx-imsx:pattern)
我们需要用的是后者,前者的话是没法区分大小写的.而后者的用法就是(?标志修饰符:格式)
其中原文中有一句话是Any letters between ? and : act as flags modifiers as wITh (?imsx-imsx).
这句话就说明了imsx-imsx的作用,标志修饰符
我们看一下刚才出现的正则(?i:.php)
?的作用是在默认的贪婪模式下尽可能多的匹配所搜索的字符串,当该字符紧跟在任何一个其他限制符 (*, +, ?, { n} , { n,} , { n,m} ) 后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,例如,对于字符串 "oooo",'o+?' 将匹配单个 "o",而 'o+' 将匹配所有 'o'。

其中i的作用为忽略大小写
.php就是我们需要匹配的部分,由于?和i的作用,那我们的正则就会在不区分大小写的情况下尽可能多的匹配所搜索的字符串,这样就达到了我们禁用所有.php后缀文件的访问了

当然还有别的参数,更多的内容大家参考一下http://perldoc.perl.org/perlre.html#Extended-Patterns

m
Treat string as multiple lines. That is, change "^" and "$" from matching the start or end of the string to matching the start or end of any line anywhere within the string.

s
Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match.
Used together, as /ms, they let the "." match any character whatsoever, while still allowing "^" and "$" to match, resPEctively, just after and just before newlines within the string.

i
Do case-insensitive pattern matching.
If use locale is in effect, the case map is taken from the current locale. See perllocale.

x
Extend your pattern's legibility by permitting whitespace and comments.

p
PReserve the string matched such that ${ ^PREMATCH} , ${ ^MATCH} , and ${ ^POSTMATCH} are available for use after matching.

g and c
Global matching, and keep the Current position after failed matching. Unlike i, m, s and x, these two flags affect the way the regex is used rather than the regex itself. See "Using regular exPressions in Perl" in perlretut for further explanation of the g and c modifiers.

其中:应该只是一个分隔符吧,不知道还有没有别的作用,如果哪个大牛知道,请告诉我.

.php就是我们要匹配的部分了,从上面的图我们..

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

上一篇: 用于过滤空白字符的几种常见的js...下一篇:JavaScript RegExp 正则表达式对...猜你在找的正则表达式相关文章 去除内容中的html2022-04-16Python正则表达式保姆式教学详细教程2022-04-16十分钟上手正则表达式 上篇2022-04-16十分钟上手正则表达式 下篇2022-04-16深入浅出正则表达式中的边界\b和\B2022-04-16轻松入门正则表达式之非贪婪匹配篇详解2022-04-16轻松掌握正则表达式findall函数详解2022-04-16正则表达式用法详解2022-04-1636个正则表达式(开发效率提高80%)2022-04-16Python正则表达式指南 推荐2022-04-16 其他相关热搜词更多phpjavapython程序员loadpost-format-gallery

若转载请注明出处: 一个正则表达式的看法(?:)
本文地址: https://pptw.com/jishu/595646.html
正则表达式 表示 非指定字符串开头的正则 精通JS正则表达式(推荐)

游客 回复需填写必要信息