^(?=.*[A-Z]+)(?=.*[a-z]+)(?=.*\d+)(?=.*[\^\$!%@#]+)[\w\^\$!%@#]{8,12}$
What we we expected a password to match this pattern. Password contains 8-12 characters. Must contains at least:
In this article we will walk thought how to test if $0bA1234 matches our string password pattern and learing lookahead.
Before we start, we need to understand stand what "Lookahead" is.
Lookahead matches characters but returns only matched position, not a matched string. On the other hand, there is no matched string return. It is the same as "start and end of line ^, $" and "start and end of word \b". Syntax of lookahead
(?=test-pattern)
Let's break down a pattern and work on small pieces.
Lest's start.
Match result
{
"content": "",
"isParticipating": true,
"groupNum": 0,
"groupName": null,
"startPos": 0,
"endPos": 0
}
Match result
{
"content": "",
"isParticipating": true,
"groupNum": 0,
"groupName": null,
"startPos": 0,
"endPos": 0
}
Match result
{
"content": "",
"isParticipating": true,
"groupNum": 0,
"groupName": null,
"startPos": 0,
"endPos": 0
}
Match result
{
"content": "",
"isParticipating": true,
"groupNum": 0,
"groupName": null,
"startPos": 0,
"endPos": 0
}
Match result
{
"content": "",
"isParticipating": true,
"groupNum": 0,
"groupName": null,
"startPos": 0,
"endPos": 0
}
Match result
{
"content": "$0bA1234",
"isParticipating": true,
"groupNum": 0,
"groupName": null,
"startPos": 0,
"endPos": 8
}
Match result
{
"content": "",
"isParticipating": true,
"groupNum": 0,
"groupName": null,
"startPos": 8,
"endPos": 8
}
Match result
{
"content": "$0bA1234",
"isParticipating": true,
"groupNum": 0,
"groupName": null,
"startPos": 0,
"endPos": 8
}
To summarize, our test string matches a strong password pattern.