iuseavalidatorthatrequiresaregextobespecified.inthecaseofvalidatingagainstanemptystring,id on ' tknowhogeneratesucharegeged
the regex ^ $ matchesonlyemptystrings (I.e.stringsoflength0).here ^ and $ arethebeginingandendofthestringanchors,RESS
ifyouneedtocheckifastringcontainsonlywhitespaces,you can use ^s * $.note thatsistheshorthandforthewhitespacharacter
Finally,in Java,matchesattemptstomatchagainsttheentirestring,soyoucanomittheanchorsshouldyouchooseto。
参考资料
非注册解决方案
youcanalsousestring.isempty (tocheckifastringhaslength0. ifyouwanttoseeifastringcontaingonlywhitespacecharacters,thenyais )