麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Regex > 正文

一個正則表達式的看法(?:)

2020-03-16 21:12:23
字體:
來源:轉載
供稿:網友
下午和kindle聊天的時候,他讓我看一個正則,問我知不知道其中?:的作用,以偶半瓶水的正則功力,不知道雜解釋給他聽了,單個一個還好理解,一起就不明白了,起碼我是沒用過..查了下資料,說說我的看法..
 
 
原正則的出現是為了實現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就是我們要匹配的部分了,從上面的圖我們..


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蜜桃av网 | 深夜免费视频 | 日本aaaa片毛片免费观看视频 | h网站在线观看 | 91成人在线免费 | 欧美性生活久久久 | 91精品国产综合久久婷婷香 | 精品亚洲夜色av98在线观看 | 国产在线观看一区二区三区 | 久久久久久久久久亚洲精品 | 性欧美极品xxxx欧美一区二区 | 91一级毛片 | 国产午夜三级一区二区三桃花影视 | 国产在线观看91一区二区三区 | 欧美成人国产va精品日本一级 | 中文字幕精品一二三四五六七八 | 国产精品久久久久国产精品三级 | 国产一区二区在线免费观看 | 91美女视频在线 | 永久免费毛片 | 成人啪啪18免费网站 | 欧美成年人视频在线观看 | av电影免费在线看 | 精品在线免费播放 | 宅男噜噜噜66国产在线观看 | 精品国产91久久久久久浪潮蜜月 | 黄色av网站在线观看 | 91网站链接 | 成熟女人特级毛片www免费 | 香蕉视频99 | 久久国产中文 | 久久久经典视频 | 久久99精品久久久久久秒播蜜臀 | 久久成人综合网 | 操碰视频在线观看 | aa国产视频一区二区 | 中文字幕亚洲情99在线 | 97久久日一线二线三线 | 福利一区二区三区视频在线观看 | 北原夏美av | 亚洲嫩草av|