I have the following regex
((\$|(\\\[)).*?(\$|(\\\])))
which should capture everything between $$ and \[\] and I tested it on http://gskinner.com/RegExr/ and it’s working.
PHP variant is (doubled backslashes)
((\$|(\\\\\[)).*?(\$|(\\\\\])))
and I would like to split my text based on that regex. How can I tell that it uses just the first (and largest group) and not these small ones?
preg_split('/((\$|(\\\\\[)).*?(\$|(\\\\\])))/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
So for text This is my $test$ for something. I should get an array
[0] => This is my
[1] => $test$
[2] => for something.
But I get
[0] => This is my
[1] => $test$
[2] => $
[3] =>
[4] => $
[5] => for something.
You would need something like this:
Output:
IMHO, your regex is (probably) wrong. It would fail for texts like
Hello $there\]. If you need to capture texts between two$s and a pair of\[and\], then you need the regexp like: