[英]Regular expression for a string of two parts separated by dot
I need to write a regular expression for a string of two parts which is separated by '.' 我需要为由'。'分隔的两部分字符串编写正则表达式。 Here below are the condition,
以下是条件,
My code : ((?=.*[az])(?=.*[AZ])(?=.*[0-9])(?=\\\\S+$).*)[.]([\\\\w]+)$
我的代码 :
((?=.*[az])(?=.*[AZ])(?=.*[0-9])(?=\\\\S+$).*)[.]([\\\\w]+)$
Input : Vijay.hello876IUY
输入 :
Vijay.hello876IUY
Actual Output : Valid data
实际输出 :
Valid data
Expected Output : Invalid data (Because 1st part doesn't contain any numbers) 预期输出 :无效数据(因为第1部分不包含任何数字)
Any one please help me to solve this... 任何人都可以帮助我解决这个问题...
You may use 您可以使用
^(?=[^.]*[a-z])(?=[^.]*[A-Z])(?=[^.]*[0-9])[a-zA-Z0-9]+\.[a-zA-Z0-9]+$
See the regex demo . 参见regex演示 。
Details 细节
^
- start of string ^
-字符串的开头 (?=[^.]*[az])
- there must be a lowercase ASCII letter after 0+ chars other than .
(?=[^.]*[az])
-除之外的0+个字符后必须有一个小写ASCII字母.
(?=[^.]*[AZ])
- there must be an uppercase ASCII letter after 0+ chars other than .
(?=[^.]*[AZ])
-除之外的0+个字符后必须有一个大写ASCII字母.
(?=[^.]*[0-9])
- there must be a digit after 0+ chars other than .
(?=[^.]*[0-9])
-除之外的0+个字符后必须有一个数字.
[a-zA-Z0-9]+
- 1+ alphanumeric chars [a-zA-Z0-9]+
-1+个字母数字字符 \\.
- a dot [a-zA-Z0-9]+
- 1+ alphanumeric chars [a-zA-Z0-9]+
-1+个字母数字字符 $
- end of string. $
-字符串结尾。 In Java: 在Java中:
s.matches("(?=[^.]*[a-z])(?=[^.]*[A-Z])(?=[^.]*[0-9])[a-zA-Z0-9]+\\.[a-zA-Z0-9]+")
Since matches()
requires a full string match, you need no ^
at the beginning and $
anchor at the end. 由于
matches()
需要完整的字符串匹配,因此您无需在开头加上^
,在结尾也不需要$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.