简体   繁体   中英

Regex not matching regex in PHP

I am currently working at a project involving regex in php. I wanted to know why or how can I get this recursive regular expression to work in 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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