Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.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 如何在preg_match中添加特定字符_Php_Regex_Preg Match All - Fatal编程技术网

Php 如何在preg_match中添加特定字符

Php 如何在preg_match中添加特定字符,php,regex,preg-match-all,Php,Regex,Preg Match All,我有以下代码: $tags = preg_match_all('~%([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)%~', $text, $matches); 它的工作原理很好,但我想能够添加“u”字符,我不知道如何添加 我将期待一些答案 Peter只需将它们添加到每组允许的字符中即可: $tags = preg_match_all('~%([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)%~', $text, $matches);

我有以下代码:

$tags = preg_match_all('~%([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)%~', $text, $matches);
它的工作原理很好,但我想能够添加“u”字符,我不知道如何添加

我将期待一些答案


Peter

只需将它们添加到每组允许的字符中即可:

$tags = preg_match_all('~%([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)%~', $text, $matches);
                                     ^                ^

那么,你想把它添加到哪里?还有什么不起作用呢?给我们举一个包含“u”的字符串的例子,你想把这个应用于它。@harke我没说什么不起作用。此时,唯一允许的字符是0-9 a-z。我只想补充一点。看起来nickhars的答案可能有用!