SyntaxFix
Write A Post
Hire A Developer
Questions
\w\- is probably the best but here just another alternative Use [:alnum:]
\w\-
[:alnum:]
if(!preg_match("/[^[:alnum:]\-_]/",$str)) echo "valid";
demo1 | demo2