This string:
$subject = '\displaystyle{\ce{Cu^{2+}{(aq)}}+\ce{Zn{(s)}}\ce{->}\ce{Cu_{(s)}}+\ce{Zn^{2+}_{(aq)}}}'
I want to capture:
- \ce{Cu^{2+}{(aq)}}
- \ce{Zn{(s)}}
- \ce{->}
- \ce{Cu_{(s)}}
- \ce{Zn^{2+}_{(aq)}}
My regex inspired by PHP - help with my REGEX-based recursive function
$pattern = '#\\\\ce\{(?:[^{}]|(?R))*}#';
I tried with
preg_match_all($pattern, $subject, $matches);
print_r($matches);
Array
(
[0] => Array
(
[0] => \ce{->}
)
)
But it doesn't work as you can see...