我在看一些代码,具有这个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