'.$mail_regex.') (;(?P.*?))? )? \] (?(?='.$mail_regex.') # if followed by (?P'.$mail_regex.') # then | (?P.*?)? # else ) \[\/mail\] ~ix' , 'replace_mail', $text);