What is the problem with regex when checking at least 1 uppercase letter, 1 lowe...
source link: https://www.codeproject.com/Questions/5330299/What-is-the-problem-with-regex-when-checking-at-le
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
at least 1 uppercase letter
at least 1 lowercase letter
at least 1 digit
at least 1 ASCII character
But I want regex to match in no specific order; for example when I typed the regex given in section (What have you tried) below, it didn't match orderless; it required the input to be in order with the regex.
What I have tried:
/([a-z][A-Z][0-9][!@#$%&])/g
And that is exactly what you are asking for: to do counting and act on rules.
So by all means use Regexes to identify if characters are present in a string, but process the rules based on that in code, don't try to do it all in a text processor.
Think about it: even if your could do exactly what you wanted, what happens next week when the rules change and require a special character as well from a specific list? Implemented in code it's trivial to understand and modify - which is not the case with any regex beyond the trivial examples!
Regex is a tool in your box - but that doesn't mean it should be used at every opportunity: a hammer can be used on screws, but a screwdriver does a better job!
The problem is that RegEx is not really designed for this, the solution is rather tricky.Quote:What is the problem with regex when checking at least 1 uppercase letter, 1 lowercase letter, 1 digit where the expression can be in no particular order
As OG answered sometime ago : How to set validation for the password in javascript using regex?[^]
Try something like :
^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%&]).*$
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]
Add your solution here
Preview
Existing Members
...or Join us
Your Email Password
Your Email Optional Password
Please subscribe me to the CodeProject newsletters
- Read the question carefully.
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
- If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
- Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Recommend
-
67
I often write documents, such as exams and lecture notes, that contain both Latin and Arabic script, often on the same line of text. This can be challenging due to the complications of mixing of LTR (left-to-right) and RTL (right-to-left) script...
-
12
PHP split string to convert a part to uppercase and others in lowercase? advertisements Does anybody have idea how to explode some string in P...
-
10
Data Wrangling Basics — Why is Regex In Python Preceded By The Letter r?Explaining the working of regular expressions in Python
-
7
HTML5 parsed as 4 with uppercase DOCTYPE in HTML Tidy Upd...
-
7
Improve Article Python – Sort by Uppercase FrequencyLast Updated : 24 Oct, 2020Given a list of strings, perform sorting by frequency of uppercase characters. ...
-
7
[Regex] How to get numbers without a letter before advertisements at first I've only discover Regex few days ago... And I am trying to...
-
4
Creating a birthdate checking regex · GitHub Instantly share code, notes, and snippets. Creating a birthdate checking regex #...
-
5
How to convert the first letter of a string to uppercase in PHP 1268 views 2 years ago PHP Use the PHP u...
-
4
First uppercase letter in a stringSkip to content
-
8
JavaScript Program to Convert the First Letter of a String into UpperCaseSkip to content...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK