正则表达式不为空 [英] Regular expression for not empty

查看:204
本文介绍了正则表达式不为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个Java正则表达式,该表达式检查给定的String是否为Empty.但是,如果用户在输入的开头意外地给定了空格,则表达式应该忽略,但以后允许空格.该表达式还应允许斯堪的纳维亚字母Ä,Ö等(小写和大写).

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 beginning of the input, but allow whitespaces later on. Also the expression should allow scandinavian letters, Ä,Ö and so on, both lower and uppercase.

我已经用Google搜索过,但是似乎没有什么适合我的需求.请帮忙.

I have googled, but nothing seems ro quite fit on my needs. Please help.

推荐答案

您还可以使用正面提前断言以断言该字符串至少有一个非空白字符:

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

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

在Java中,您需要

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

这篇关于正则表达式不为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆