php - PHP 中\s 匹配的空格是什么?

标签 php regex

PHP 中转义序列\s 匹配的完整字符列表是什么? 一些正则表达式风格在此转义序列中包括垂直空格和其他字符。

最佳答案

来自 pcrepattern specifications页:

Generic character types

\s     any white space character

For compatibility with Perl, \s did not used to match the VT character (code 11), which made it different from the the POSIX "space" class. However, Perl added VT at release 5.18, and PCRE followed suit at release 8.34. The default \s characters are now HT (9), LF (10), VT (11), FF (12), CR (13), and space (32), which are defined as white space in the "C" locale. This list may vary if locale-specific matching is taking place. For example, in some locales the "non-breaking space" character (\xA0) is recognized as white space, and in others the VT character is not.

因此 \s 将匹配 5 个字符以及更多字符,具体取决于:

  1. PCRE 库版本
  2. 区域设置

This test比较不同版本的 PHP 的 preg_match 结果。

关于php - PHP 中\s 匹配的空格是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5471644/

相关文章:

c# - 与任何特殊字符匹配的强密码正则表达式

javascript - pattern.test 不是函数

php - cakePHP 找不到验证处理程序

php - 无法使用 file_get_contents ('php://input' 检索原始发布数据)

PHP 服务器发送事件减少流量

php - 远程访问EC2上的mysql

python - 迭代并替换元组python行中的单词

javascript - 换行符匹配正则表达式 -/[\r\n]/与/[\n]/相同吗?

java - 如何在每个大写字母之间添加空格?

php - 从时间戳最新的表中选择