How do I allow spaces in this regex?

前端 未结 6 1357
渐次进展
渐次进展 2021-01-12 02:05

I\'m such an amateur at regex, how do I allow spaces(doesn\'t matter how many) in this regex?

if(preg_match(\'/[^A-Za-z0-9_-]/\', $str)) return FALSE;
         


        
6条回答
  •  猫巷女王i
    2021-01-12 02:55

    If you need to ALLOW only space you'll need '/ /'

    If you need to ALLOW any whitespace char (space, tab, newline) - use '/\s/'

    And if you need to add a space to your pattern (means to ignore space) - use /[^A-Za-z0-9_\ -]/

提交回复
热议问题