Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在正则表达式搜索中不包含任何字母字符_Php_Regex - Fatal编程技术网

Php 在正则表达式搜索中不包含任何字母字符

Php 在正则表达式搜索中不包含任何字母字符,php,regex,Php,Regex,我有一个有效的正则表达式代码,但它不包括非字母字符。我该如何包括这些 $text = "i have one treehouse. i'm the one. I have two cats."; preg_match_all('/[\w\s]+?\bone\s?[\w\s]*?\./', $text, $array); print_r($array); 预期结果 实际结果 $array[0]=“我有一个树屋。”; $array[1]=“我就是那个” 您需要在character类中包含” \b

我有一个有效的正则表达式代码,但它不包括非字母字符。我该如何包括这些

$text = "i have one treehouse. i'm the one. I have two cats.";
preg_match_all('/[\w\s]+?\bone\s?[\w\s]*?\./', $text, $array);

print_r($array);
预期结果

实际结果

$array[0]=“我有一个树屋。”;

$array[1]=“我就是那个” 您需要在character类中包含

\b[\w'\s]+?\bone\s?[\w\s]*?\.


您当前正在使用一个字符组:
[\w\s]
。为此,请添加要包含的特殊字符:
[\w\s',!]
等待。不久前我看到了一篇类似的帖子,我认为
[]
是一个字符类,列出了您想要的字符。把你允许的字符放在里面。如果你试着用
(?你能把整个preg\u match\u all都包括进去吗?我很难把这部分代码放在哪里。如果句子以问号或感叹号结尾,我需要它来匹配。我也不希望它在逗号处被截断。
$array[0] = "i have one treehouse.";
$array[1] = "m the one"; <---cuts off at the single quote
\b[\w'\s]+?\bone\s?[\w\s]*?\.
preg_match_all("~\b[\w'\s]+?\bone\s?[\w\s]*?\.~", $str, $matches);