Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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 正则表达式this或this_Php_Regex - Fatal编程技术网

Php 正则表达式this或this

Php 正则表达式this或this,php,regex,Php,Regex,例如: preg_match_all('/example\.com\/lamp\/(\w+)/i', $string, $matches); 我想要的是: 它应该寻找灯,也应该寻找汽车。 它应该包含灯或汽车 我知道这很简单,我应该使用谷歌。 但是我不知道我应该在google上搜索什么。在正则表达式中,可以使用管道作为逻辑OR运算符 请阅读以下内容: 您可以使用|符号匹配多个可能字符串中的一个。您也可以匹配任何字符串。此:[^\/]+将匹配除/ 这将看起来像一个或多个单词字符 如果只想使灯部件

例如:

preg_match_all('/example\.com\/lamp\/(\w+)/i', $string, $matches);
我想要的是:

它应该寻找灯,也应该寻找汽车。 它应该包含灯或汽车 我知道这很简单,我应该使用谷歌。
但是我不知道我应该在google上搜索什么。

在正则表达式中,可以使用管道作为逻辑OR运算符

请阅读以下内容:


您可以使用|符号匹配多个可能字符串中的一个。

您也可以匹配任何字符串。此:[^\/]+将匹配除/


这将看起来像一个或多个单词字符

如果只想使灯部件不固定,则应为:

preg_match_all('/example\.com\/(\w+)\/(\w+)/i', $string, $matches);

汽车哪里你能给出一些URL和你期望正则表达式返回的内容吗?@FelixKling-酷,我不知道那个快捷方式。谢谢
preg_match_all('/example\.com\/[^\/]+\/(\w+)/i', $string, $matches);
preg_match_all('/example\.com\/(\w+)\/(\w+)/i', $string, $matches);