Regular Expression

0
Hi, I have the below regular expression used in one of the java actions to check the password strength. Can somone tell me what this translates to? public static final Pattern pattern = Pattern.compile("^.(?=.{8,})(?=.[a-z])(?=.[A-Z])(?=.[\W_]).*$"); Thanks Aravind
asked
3 answers
2

Aravind,

See below for an explanation of the regex:

^.(?=.{8,})(?=.[a-z])(?=.[A-Z])(?=.[\W_]).*$

^ asserts position at start of the string
. matches any character (except for line terminators)
Positive Lookahead (?=.{8,})
Assert that the Regex below matches
.{8,} matches any character (except for line terminators)
{8,} Quantifier — Matches between 8 and unlimited times, as many times as possible, giving back as needed (greedy)
Positive Lookahead (?=.[a-z])
Assert that the Regex below matches
. matches any character (except for line terminators)
Match a single character present in the list below [a-z]
a-z a single character in the range between a (ASCII 97) and z (ASCII 122) (case sensitive)
Positive Lookahead (?=.[A-Z])
Assert that the Regex below matches
. matches any character (except for line terminators)
Match a single character present in the list below [A-Z]
A-Z a single character in the range between A (ASCII 65) and Z (ASCII 90) (case sensitive)
Positive Lookahead (?=.[\W_])
Assert that the Regex below matches
. matches any character (except for line terminators)
Match a single character present in the list below [\W_]
\W matches any non-word character (equal to [^a-zA-Z0-9_])
_ matches the character _ literally (case sensitive)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
answered
2

For all your regex needs, use regexr (or any other site like it). For your specific regex: http://regexr.com/3ebs4

answered
2

You could also take a look at: regexper

answered