$input = "ADW-CFS-WE XY CI SLA Def No SLANAME CI Max Outage Service"; preg_match_all('/[AZ]+-[AZ-]+/', $input, $matches); foreach ($matches[0] as $m) { echo $matches . "\n"; }
Please note that in these solutions only capital letters AZ are allowed. If not, insert the correct character class. For example, if you want to allow arbitrary letters (for example, a and Ä), replace [AZ] with \p{L} .
source share