Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.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 与PCRE模式文本中的分隔符匹配的PCRE模式_Php_Regex_Pcre - Fatal编程技术网

Php 与PCRE模式文本中的分隔符匹配的PCRE模式

Php 与PCRE模式文本中的分隔符匹配的PCRE模式,php,regex,pcre,Php,Regex,Pcre,我正在寻找一个PCRE模式,它将匹配任何有效PCRE模式的分隔符之间的文本,而不考虑使用的分隔符和修饰符。据我所知,有四个成对的分隔符:(),[],{},。所有其他允许的字符只使用两次。根据,我们可以使用任何非字母数字、非空白、非反斜杠字符。因此,这种模式应该有效: / ^ (?=([^a-zA-Z0-9\s\\\\])) # make sure the pattern begins with a valid delimiter # and ca

我正在寻找一个PCRE模式,它将匹配任何有效PCRE模式的分隔符之间的文本,而不考虑使用的分隔符和修饰符。

据我所知,有四个成对的分隔符:
()
[]
{}
。所有其他允许的字符只使用两次。根据,我们可以使用任何非字母数字、非空白、非反斜杠字符。因此,这种模式应该有效:

/
^
(?=([^a-zA-Z0-9\s\\\\])) # make sure the pattern begins with a valid delimiter
                         # and capture it into group 1
(?|                      # alternation for different delimiter types
                         # each alternative captures the pattern into group 2
  \((.*)\)               # handle (...)
|
  \[(.*)\]               # handle [...]
|
  \{(.*)\}               # handle {...}
|
  <(.*)>                 # handle <...>
|
  .(.*)\1                # handle all other delimiters with a backreference
)
[imsxeADSUXu]*           # allow for modifiers
$
/xs
然后,您将在
$matches[2]
中找到所需的结果


当然,这将接受一组无效的模式,因为它不能确保分隔符不会在模式中的某个位置出现得更快。

@JasonMcCreary在
/text/
中匹配
文本
{text}iu
等。还请向我们展示您尝试过的无效模式。另外,您知道,如果要确保模式有效,您需要实际解析正则表达式?@m.buettner我试图寻找用于此目的的“标准”模式,但找不到。@m.buettner让这种情况下的有效性仅由分隔符和修饰符的有效性来确定
preg_match($pattern, $input, $matches);