简体   繁体   English

正则表达式与PHP中的正则表达式不匹配

[英]Regex not matching regex in PHP

I am currently working at a project involving regex in php. 我目前正在一个涉及regex的项目中工作。 I wanted to know why or how can I get this recursive regular expression to work in PHP: 我想知道为什么或如何让此递归正则表达式在PHP中工作:

/\(((?:(?:[^?+*{}()[\]\\|]+|\\.|\[(?:\^?\\.|\^[^\\]|[^\\^])(?:[^\]\\]+|\\.)*\]|\((?:\?[:=!]|\?<[=!]|\?>)?(?1)??\)|\(\?(?:R|[+-]?\d+)\))(?:(?:[?+*]|\{\d+(?:,\d*)?\})[?+]?)?|\|)*)\)/

It should match this text (for example): 它应与以下文本匹配(例如):

{{"test":"([a-f0-9]{32})"},{"test2":"([a-z]{3})"}}

And the given results should be an array with: 给定的结果应该是一个包含以下内容的数组:

  • [a-f0-9]{32}
  • [az]{3}

EDIT: 编辑:

$from = '{{"test":"([a-f0-9]{32})"},{"test2":"([a-z]{3})"}}'; 
preg_match_all("/(((?:(?:[^?+*{}()[]\\|]+|\\.|[(?:\^?\\.|\^[^\]|[^\\^])(?:[^]\]+‌​|\\.)*]|((?:\?[:=!]|\?<[=!]|\?>)?(?1)??)|(\?(?:R|[+-]?\d+)))(?:(?:[?+*]|\{\d+‌​(?:,\d*)?\})[?+]?)?|\|)*))/", $from, $output_array, PREG_OFFSET_CAPTURE); 
var_dump($output_array);

Why this complex? 为什么这么复杂?

preg_match ('/\:"\((.*)\)"/', $search, $ matches);

It seems you just want the values between :"( and )" ? 看来您只想要:"()"之间的值?

The matches are in $matches. 匹配项为$ matches。

See http://php.net/manual/en/function.preg-match.php 参见http://php.net/manual/en/function.preg-match.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM