doufenyu7610 2015-08-30 12:17
浏览 257

PHP正则表达式中的\ s和[:space:]有什么区别?

In my PHP code I've been using [:space:] and [:print:] for matching space and non-space characters respectively. I however came across one case where preg_match was unable to find a match even though it should have. Replacing [:space:] with \s solved the problem. Due to this I realized all my other uses of [:space:] in the code could fail unexpectedly at some point in the future and so embarked on replacing all of them with \s.

My question is why did [:space:] fail where \s worked? The original regexp was:

'%\[/row\][[:space:]]+<!-- related_products_section -->[[:space:][:print:]]+<!-- end_related_products_section -->%m'

which I changed into:

'%\[/row\][\s]+<!-- related_products_section -->[\s[:print:]]+<!-- end_related_products_section -->%m'

Another question arising is what is the non-posix equivalent of [:print:]?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 怎么把多于硬盘空间放到根目录下
    • ¥15 Matlab问题解答有两个问题
    • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
    • ¥15 gsoap生成onvif框架
    • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
    • ¥15 stm32的can接口不能收发数据
    • ¥15 目标检测算法移植到arm开发板
    • ¥15 利用JD51设计温度报警系统