简体   繁体   English

由点分隔的两部分字符串的正则表达式

[英]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, 以下是条件,

  1. <<1st part>>.<<2nd part>> : Example- Time01.Sheet <<<第一部分>>。<<<第二部分>>:示例-Time01.Sheet
  2. 1st part should contain alpha numeric characters and it must contain at least 1 uppercase alphabet, 1 lowercase alphabet, and 1 number. 第一部分应包含字母数字字符,并且必须至少包含1个大写字母,1个小写字母和1个数字。
  3. 2nd part should contain alpha numeric characters. 第二部分应包含字母数字字符。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM