gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:20:11 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com