regular expression to match an empty (or all whitespace) string

前端 未结 7 1255
孤城傲影
孤城傲影 2021-01-12 10:04

i want to match a string that can have any type of whitespace chars (specifically I am using PHP). or any way to tell if a string is empty or just has whitespace will also h

7条回答
  •  Happy的楠姐
    2021-01-12 10:49

    You don't really need a regex

    if($str == '') { /* empty string */ }
    elseif(trim($str) == '') { /* string of whitespace */ }
    else { /* string of non-whitespace */ }
    

提交回复
热议问题