Your question is not clear. The regular expression, as it is, will succeed if $str has any character in it that is not A-Za-z0-9_- . Since the space is not one of these characters, the regular expression will match, and the whole statement returns FALSE .
If this is not what you want and you want your regular expression to match, if $str has any character that is not in A-Za-z0-9_- , or a space, then you need to change it to A-Za-z0-9_ - (note the space between the underscore and hyphen). That way, when your string has a character that is not A-Za-z0-9_ - , the regular expression will match, and your statement will return FALSE . If your line consists of all A-Za-z0-9_ - , then the regular expression will not match, and your processing will continue to the next line.
Edit: Here is an example: if your string is abc123def , at present the regular expression will not match and you will not return FALSE . If your string is abc123 def , the regex will match and the statement will return FALSE . If you change the character class to A-Za-z0-9_ - , the regular expression will not match both abc123def and abc123 def , and you will not return FALSE .
Canspice
source share