<?php $re = '/(\bLAB_[0-9A-F]{2}\b)|(\bLAB_[0-9A-F]{4}\b)/'; $str = 'LAB_FF12'; preg_match($re, $str, $matches); var_dump($matches); $substitutes = ["", "DAB", "HAD"]; For($i=1; $i<count($matches); $i++){ If($matches[$i] != ""){ $result = $substitutes[$i] . substr($matches[$i],3); Break; } } Echo $result;
You have javascript disabled. You will not be able to edit any code.