UPDATE: I'm making progress, but this is hard!
The test text will be valid[REGEX_EMAIL|REGEX_PASSWORD|REGEX_TEST]
.
(The real life text is required|valid[REGEX_EMAIL]|confirmed[emailconfirmation]|correct[not in|emailconfirmation|email confirmation]
.)
([^|]+)
saves REGEX_EMAIL, REGEX_PASSWORD and REGEX_TEST in an array.
^[^[]+\[
matches valid[
\]
matches ]
^[^[]+\[
+ ([^|]+)
+ \]
doesn't save REGEX_EMAIL, REGEX_PASSWORD and REGEX_TEST in an array.
How to solve?
Why is it important to try to everything with a single regular expression? It becomes much easier if you extract the two parts first and then split the strings on |
using explode:
$s = 'valid[REGEX_EMAIL|REGEX_PASSWORD|REGEX_TEST]';
$matches = array();
$s = preg_match('/^([^[]++)\[([^]]++)\]$/', $s, $matches);
$left = explode('|', $matches[1]);
$right = explode('|', $matches[2]);
print_r($left);
print_r($right);
Output:
Array
(
[0] => valid
)
Array
(
[0] => REGEX_EMAIL
[1] => REGEX_PASSWORD
[2] => REGEX_TEST
)