php regex to match a single letter after digits
I’ve got the following regex to see if $string contains digits followed by letters. However, I need it to check only that it contains 1 letter after the numeric value. Although the code below works, if $string was to be 28AB then it will also match the regex but it shouldn’t, it should only match any numeric value followed by a single letter.
$string = “28A”;
$containsSpecial = preg_match(‘/[d\^a-zA-Z]/’, $string);
Try this.Your code uses
 which can match any character out of the list provided.Also use anchors to make a strict match and no partial matches.See here