我在看一些代碼,具有這個pregmatch是如何工作的?
preg_match('/\[youtube ([[:print:]]+)\]/', $content, $matches)
$content
可能是一個鏈接,如* HTTP://www.youtube.com/watch V = some_video *
我可以看到它的過濾youtube視頻,但我不明白它是如何做的。更具體地說,[:print:]
的作用是什麼?
我在看一些代碼,具有這個pregmatch是如何工作的?
preg_match('/\[youtube ([[:print:]]+)\]/', $content, $matches)
$content
可能是一個鏈接,如* HTTP://www.youtube.com/watch V = some_video *
我可以看到它的過濾youtube視頻,但我不明白它是如何做的。更具體地說,[:print:]
的作用是什麼?
你的答案就在這裏:http://www.php.net/manual/en/function.preg-match-all.php#81559
「[:打印:] - 打印字符,包括空格」
這裏的箱圖中的實驗。
/\[youtube ([[:print:]]+)\]/
│ │ │ │ │
│ │ │ │ └─ close the matched string
│ │ │ └──────────── start the character class
│ │ └────────────── open the matched string
│ └─────────────────────── literal square bracket
└───────────────────────── start the regexp
重要的是圓括號內的部分。這與您的編程語言相匹配,以便作爲變量重用,以便您可以構建替換網址。
您是否閱讀過['re_format(7)'](http://www.freebsd.org/cgi/man.cgi?query=re_format)手冊頁以查看字符類如何工作? – ghoti
老實說,這是我第一次瞭解角色類。感謝您的鏈接。 – KalenGi