Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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,如何使用正则表达式捕获除空间以外的所有内容 例如,我有Hello-Word 使用什么正则表达式输出HelloWord (我正在使用Regex和php) 致以最诚挚的问候 preg_replace('/\s+/', '', $str) 差不多了。将其更改为:preg_replace('/\s+/','$str)(PHP没有preg_replace_all()函数。而且\s不需要在字符类中。)而且空间实际上是[],您已经回答了空白(可能是OP一直在寻找的),可能是UTF-8编码输入?在这种情况下

如何使用正则表达式捕获除空间以外的所有内容

例如,我有
Hello-Word

使用什么正则表达式输出
HelloWord

(我正在使用Regex和php) 致以最诚挚的问候


preg_replace('/\s+/', '', $str)

差不多了。将其更改为:
preg_replace('/\s+/','$str)
(PHP没有
preg_replace_all()
函数。而且
\s
不需要在字符类中。)而且空间实际上是
[]
,您已经回答了空白(可能是OP一直在寻找的),可能是UTF-8编码输入?在这种情况下,OP可能希望使用
\p{Z}
\p{Zs}
。只使用正则表达式而不使用php是不可能做到的?无论如何,您需要一些语言,正则表达式只是语言的一个功能可能与的重复
<?php
$string = "Hello Word";
$string = preg_replace('/ /', '', $string);
echo $string;
//HelloWord
?>