我需要为ASCII字符32-90(包括32-90)进行正则表达式匹配。
我尝试了以下操作,但似乎没有返回任何结果。
preg_match("/^['x20-'x5A]+$/u", $input)
其思想是从十六进制20
到十六进制5a
。我把这些从http://www.asciitable.com/
我有一个测试的地方http://www.phpliveregex.com/p/2Dh
您当前的范围只支持大写字母,因此您需要/i
修饰符:
$input = 'adddd ### AAAA????';
preg_match('/^['x20-'x5A]+$/i', $input); // int(1)
或者,添加范围中的额外字母:
preg_match('/^['x20-'x5A'x61-'x7A]+$/', $input))
您需要使用preg_match的第三个参数将其分配给变量
preg_match("/^['x20-'x5A]+$/u", $input, $matches)
此函数的标准返回为1或0/FALSE
例如。。。
if(preg_match("/^['x20-'x5A]+$/u", $input, $matches))
{
var_dump($matches);
}