Regular expression for not empty

后端 未结 7 1240
执笔经年
执笔经年 2020-12-28 18:31

I need a Java regular expression, which checks that the given String is not Empty. However the expression should ingnore if the user has accidentally given whitespace in the

相关标签:
7条回答
  • 2020-12-28 19:19

    You can also use positive lookahead assertion to assert that the string has atleast one non-whitespace character:

    ^(?=\s*\S).*$
    

    In Java you need

    "^(?=\\s*\\S).*$"
    
    0 讨论(0)
提交回复
热议问题