正则表达式不起作用,是什么?=。意思

时间:2021-04-06 01:58:35

hi i a beginner in working with regular expressions i have a regular expression for email as i have copied that from some other source

我是初学者,使用正则表达式我有一个正则表达式的电子邮件,因为我从其他来源复制了

(?=.[@])

it is not working i wanted to test different combinations so i m trying to match only @ value for the input field but is not working. if i write the same to the numerical values it is working in the password field

它不工作我想测试不同的组合,所以我试图只匹配输入字段的@值但不起作用。如果我将相同的值写入密码字段中的数值

((?=.[0-9]+).{6,})

***Note:***As i am practicing application of different methods and trying to get a clear idea about regex please ignore the common ethics like the password regex i chose.

***注意:***由于我正在练习不同方法的应用并试图清楚地了解正则表达式,请忽略我所选择的密码正则表达式这样的常见道德。

Moreover i wanted to know why this ?=. used preceding the pattern

而且我想知道为什么这个?=。在模式之前使用

Thanks in advance

提前致谢

2 个解决方案

#1


Your current regex expressions are not doing what you think:

你当前的正则表达式没有按照你的想法行事:

Email:

(?=.[@])
<!-- matches a single character followed by @, e.g. a@ -->

Password:

((?=.[0-9]+).{6,})
<!-- matches a single character followed by at least 5 digits, e.g. a12345 -->

You could try using this for email: (?=.*[@].*\..*)
And this for password: ((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})

您可以尝试将此用于电子邮件:(?=。* [@]。* \ .. *)这是密码:((?=。* \ d)(?=。* [az])(?=。 * [AZ])(?=。* [@#$%])。{6,20})

#2


Try this: Email validation using regular expression in JSF 2 / PrimeFaces

试试这个:使用JSF 2 / PrimeFaces中的正则表达式进行电子邮件验证

[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]

#1


Your current regex expressions are not doing what you think:

你当前的正则表达式没有按照你的想法行事:

Email:

(?=.[@])
<!-- matches a single character followed by @, e.g. a@ -->

Password:

((?=.[0-9]+).{6,})
<!-- matches a single character followed by at least 5 digits, e.g. a12345 -->

You could try using this for email: (?=.*[@].*\..*)
And this for password: ((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})

您可以尝试将此用于电子邮件:(?=。* [@]。* \ .. *)这是密码:((?=。* \ d)(?=。* [az])(?=。 * [AZ])(?=。* [@#$%])。{6,20})

#2


Try this: Email validation using regular expression in JSF 2 / PrimeFaces

试试这个:使用JSF 2 / PrimeFaces中的正则表达式进行电子邮件验证

[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]