Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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/17.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 重复regex模式而不存储它_Php_Regex - Fatal编程技术网

Php 重复regex模式而不存储它

Php 重复regex模式而不存储它,php,regex,Php,Regex,我有一个正则表达式模式:[a-Ba-b0-9\-]\. 我想重复这个模式,所以我把它包装在parens中:$repeatingPattern='([A-Ba-b0-9\-]\)* 我还有另一个要捕获的正则表达式模式,所以我也将其包装在parens中:$capturePattern='(stuff)' 问题是我只想捕获$capturePattern,而不想捕获$repeatingPattern: preg_match('/' . $repeatingPattern . $capturePatter

我有一个正则表达式模式:
[a-Ba-b0-9\-]\.

我想重复这个模式,所以我把它包装在parens中:
$repeatingPattern='([A-Ba-b0-9\-]\)*

我还有另一个要捕获的正则表达式模式,所以我也将其包装在parens中:
$capturePattern='(stuff)'

问题是我只想捕获
$capturePattern
,而不想捕获
$repeatingPattern

preg_match('/' . $repeatingPattern . $capturePattern . '/', $string, $matches)

换句话说,如果
$repeatingPattern
不影响
$matches
中存储的内容,我会更喜欢它。这可能吗?我知道重复正则表达式模式的唯一方法是使用paren,它也用于捕获。

您可以在第一个正则表达式中使用非捕获组:

$repeatingPattern = '(?:[A-Ba-b0-9\-]\.)*';

非捕获组的语法是
(?:…)
哪些组不捕获。

您可以使用。

或lookback:
(?这假设OP在
$capturePattern
之前需要
$repeatingPattern
。假设
$repeatingPattern
是用
*
量化的,这意味着可能没有或更多,不需要。