Please explain to me when $string
will be true
. I cannot find all information by Google.
preg_match('#^[0-9a-f]{32}$#', $string)
{32}
means $string
must contain 32 chars? [0-9a-f]
is mean that only numeric and lower case must be in $string
?
I have validation where I check if preg_match
is true
. But I cannot understand $string
template.
$string
is the subject you are searching on.
$pattern = '/0x[\da-f]/i';
preg_match($pattern, $subject, $matches);
print_r($matches);
Read the docs. As for return values of this function, if you just care for existence of a match...
preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred.
I'm pretty sure you can't use the # symbol for regex, you need a forward slash. I have:
if(preg_match("/[^0-9]/", $data)){$data=null}
This will evaluate if the input data is a number. There is A LOT you can do with regex ... what is it you need to do? Perhaps a more specific question about what you need it to do and what you have tried?