如何检查是否有符号 - 在PHP中出现正则表达式?

This if condition:

if (preg_match('/^[a-zA-Z_]+\z/', $network_path)) 

Skips strings like: bla-bla-bla-bla

How can I Improve this regex so it would accept strings like above.. ?

This [a-zA-Z_] is a character class. This construct matches one character from those defined inside the square brackets.

So this class matches a to z, A to Z and the underscore. If you want to match also a dash, you just need to add it to the class. But be careful, - is a special character inside a character class, so if you want to match it literally you need to escape it or put it to the start or the end of the class.

if (preg_match('/^[-a-zA-Z_]+\z/', $network_path))

or

if (preg_match('/^[a-zA-Z_-]+\z/', $network_path))

or

if (preg_match('/^[a-zA-Z\-_]+\z/', $network_path))
if (preg_match('/^[-a-zA-Z_]+\z/', $network_path)) 

(Not a PHP guy, so ymmv, but...)

The characters inside the [] are treated as a character class by most perl compatible regex engines. Character classes can be followed my modifiers like the +, which will accept 1 or more characters from within that class. So if you simply add the dash inside the character class, you should get what you're looking for (or at least, you do in ruby!)