Regular expression for a single character corresponding to a single character

advertisements

I can't get the regular expression for matching with exactly single character.

$strings=array('hgasdfgh','a','1','addsa');
foreach($strings as $string)
{
$result=preg_match('/[a-z]/',$string);
if($result)
echo "match";
else
echo "no";}

This code match with 1st 2nd and 4th string of array. But i need it for just match with 2nd item(any character).


Try this expression

^[a-z]$

^ indicates the beginning of the string and $ the end of it.