Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要执行一个 if 语句来过滤一些字符串。
如果字符串包含0-9, whitespace, commas or brackets我想让它们通过。所以这个字符串应该通过 -
0-9, whitespace, commas or brackets
[[1,1],[2,3]]
但是,如果字符串是,或者说,或者Hello World因为它们包含的字符不是[Hello World][1, $]0-9, whitespace, commas or brackets
Hello World
[Hello World]
[1, $]
那么最好的方法是什么?
if (preg_match("/[^\d\s,\[\]]/", $string)) { //Invalid }