For an example I have tons of regex as simple I wrote:
php > var_dump( preg_split('/[:reg\s{}]+/', ':reg{/^[a-zA-Z]*$/}') );
array(3) {
[0] =>
string(0) ""
[1] =>
string(13) "/^[a-zA-Z]*$/"
[2] =>
string(0) ""
}
I want remove empty arrays [0] => string(0) ""
for example a result should be:
php > var_dump( preg_split('????', ':reg{/^[a-zA-Z]*$/}') );
array(3) {
[0] =>
string(13) "/^[a-zA-Z]*$/"
}
I know array_filter()
function when remove empty arrays, but I want using regular expression only.
Just use the flag PREG_SPLIT_NO_EMPTY
:
preg_split('/[:reg\s{}]+/', ':reg{/^[a-zA-Z]*$/}', -1, PREG_SPLIT_NO_EMPTY);
See the doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With