<?php
$string = 'This is my test string with an <img test /> image. <test />';
$pattern = '/<([a-zA-Z0-9]*)(.*)\/>/i';
$count = preg_match_all($pattern, $string, $matches, PREG_SET_ORDER);
print_r($matches);
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Array
(
[0] => Array
(
[0] => <img test /> image. <test />
[1] => img
[2] => test /> image. <test
)
)