Marius Eugen Circiu
Marius Eugen Circiu

Reputation: 31

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:

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);

Upvotes: 2

Views: 75

Answers (1)

Ben
Ben

Reputation: 683

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

Upvotes: 3

Related Questions