Ora*_*ind 15 php regex validation preg-match
我想检查字符串是否是文件名(名称为DOT ext).
文件名不能包含 / ? * : ; { } \
你能建议我在preg_match()中使用正则表达式吗?
Ric*_*dle 17
干得好:
"[^/?*:;{}\\]+\\.[^/?*:;{}\\]+"
Run Code Online (Sandbox Code Playgroud)
"一个或多个不是这些字符的字符,然后是一个点,然后是一些不是这些字符的字符."
(只要你确定这个点确实是必需的 - 如果没有,那就简单地说: "[^/?*:;{}\\]+"
$a = preg_match('=^[^/?*;:{}\\\\]+\.[^/?*;:{}\\\\]+$=', 'file.abc');
^ ... $ - begin and end of the string
[^ ... ] - matches NOT the listed chars.
Run Code Online (Sandbox Code Playgroud)