如何在正则表达式中添加点 [英] How to add dot to regex

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

问题描述

@Pattern(regexp="^\\w{8,}")
private String username;

此模式只能由数字、字母和下划线字符组成.

This pattern can only consist of numbers, letters and the underscore character.

如何在模式中添加点 (.)

How can I add the dot (.) to the pattern

谢谢

推荐答案

试试这个,如果你明确定义所有有效字符可能更容易理解:

Try this, it might be easier to understand if you explicitly define all valid characters:

@Pattern(regexp="^[A-Za-z0-9_.]{8,}")
private String username;

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

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