I have some php code like this:
$input = "
__HELLO__
__HAPPY_BIRTHDAY__
__HELLO____HAPPY_BIRTHDAY__";
preg_match_all('/__(\w+)__/', $input, $matches);
print_r($matches[0]);
Currently the result of $matches[0]
is this:
Array
(
[0] => __HELLO__
[1] => __HAPPY_BIRTHDAY__
[2] => __HELLO____HAPPY_BIRTHDAY__
)
As you can see my regex is interpreting __HELLO____HAPPY_BIRTHDAY__
as one match, which I don't want.
I want the matches to return this:
Array
(
[0] => __HELLO__
[1] => __HAPPY_BIRTHDAY__
[2] => __HELLO__
[3] => __HAPPY_BIRTHDAY__
)
Where __HELLO____HAPPY_BIRTHDAY__
is split into __HELLO__
and __HAPPY_BIRTHDAY__
. How can I do this?
(Each line will only ever have one underscore in between the outer underscores e.g. __HAPPY__BIRTHDAY__
is illegal)