creating a regex that captures these rules [duplicate] - regex

This question already has answers here:
Regex to validate password strength
(11 answers)
Closed 7 years ago.
I have the following password requirements I'm trying to express in a regex expression and I'm struggling. Any help appreciated!
Passwords must contain characters from 3 of the following 4 types:
upper case letters
lower case letters
numerals
special characters
I've found some similar examples and if my knowledge of regex was stronger I could figure it out but I haven't found one that has the "3 of 4" requirement.
Edit:
Ok here is what I'm using for now, I'm currently testing it. Does this look right?
passwordStrengthRegularExpression="(?=^[^\s]{8,}$)((?=.?\d)(?=.?[A-Z])(?=.?[a-z])|(?=.?\d)(?=(.\W){1,})(?=.?[a-z])|(?=(.\W){1,})(?=.?[A-Z])(?=.?[a-z])|(?=.?\d)(?=.?[A-Z])(?=(.\W){1,}))^.*"

Analog to https://stackoverflow.com/a/5142164/2606322 I would do the following for all 4 requirements
^(?=.*[A-Z])(?=.*[!##$&*])(?=.*[0-9])(?=.*[a-z]).{8}$
and then add the other 4 (3 of 4) possibilities or-ed together like
^
((?=.*[A-Z])(?=.*[!##$&*])(?=.*[0-9])(?=.*[a-z]).{8})|
((?=.*[!##$&*])(?=.*[0-9])(?=.*[a-z]).{8})|
((?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8})|
((?=.*[A-Z])(?=.*[!##$&*])(?=.*[a-z]).{8})|
((?=.*[A-Z])(?=.*[!##$&*])(?=.*[0-9]).{8})|
$
just in one line. Ugly but might work. And, of course, replace the !##$&* with the set of your liking.

Related

Postgresql regex replace numbers to asterisks [duplicate]

This question already has answers here:
Regex to mask characters except first two and last two characters in Java
(4 answers)
Closed 5 months ago.
I use Postgresql and need to replace numbers to asterisk at database layer. Howerver I'm new to learn regex and seems to be hard to do this with my current knowledge.
I will have in my database 16 numbers varchar and I need to replace middle numbers with asterisk.
Example.
123467812345678 -> 12**********5678
Could someone tell me how regex for this should look like in postgresql ?
Thanks in advance
Thanks to #Wiktor Stribiżew:
SELECT regexp_replace('123467812345678', '(?<=..).(?=....)', '*','g');

How to match a int less than 50 in regx [duplicate]

This question already has answers here:
Using regular expressions to validate a numeric range
(11 answers)
Closed 2 years ago.
I want to match a url like "index.html\index_1.html\index_12.html\index_49.html\index_n.html
and the n must <50 not be 50
You can achieve this by using - index_[1-4]?\d\.html as your regex.
What this does is it first limits the first digit of two to the numbers 1-4 then accepts any other following digit. The ? makes it so that the digit may be skipped if it cannot be found
regex101 link - https://regex101.com/r/BwMCdu/1 which has a few examples
Try the following:
(((index)|(index_[0-9])|(index_[0-4][0-9])).html)
You can use [1-4]?[0-9]
index.html\index_1.html\index_12.html\index_49.html\index_[0-4]?[0-9].html$

validation format - Reges expression [duplicate]

This question already has answers here:
How do I match an entire string with a regex?
(8 answers)
Closed 5 years ago.
I believe my validation is correct however it is not working.
My regular expression pattern is
ValidationExpression= "(I|II|III|IV)[DEF]?"
Basically, the user should put any of the first options then with optional D, E or F
Valid text Example: IIIC
Thank you
I don't know much about regex, but I did a quick bit of googling and came up with this:
https://regex101.com/r/KYpVbk/1
It explains how it works at the side :)

Using regex to restrict user input [duplicate]

This question already has answers here:
javascript regexp for numbers between 00-59 (seconds)
(4 answers)
Closed 6 years ago.
There is a particular field in my application where a user will be asked to enter a time for a job to be run (like HH:MM) for the MM field, I want the user to enter a number in the range 0-59 ONLY. How should I pattern match this with regexp ?
Try using this regex:
^[0-5]?[0-9]$
This will allow an optional first digit of 0-5 followed by any second digit.
But I would rather just check the numerical value in your code (JavaScript), since this is much easier to handle there.
Regex101

^[.1-9]*\d$ allows multiple dots [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Regex for floating point?
I am trying to use the regex.
The valid strings are:
1
11
5
12222222233
1.2
.5
1222.33444
12234.456
0
Invalid Strings are
.
-2
san
2s2
S2S
ssss2ssss
25535535TY
But this regex does not qualify to test multiple dots (.)
such as
1......5,
5..2233
1223...5
This accepts these values as valid string. Please help me how to fix this issue with reg.
Note, the above validation should be passed.
How about that regex: \d*(\.\d+)?
EDIT
This regex \d*(\.\d+)? will allow empty values too.
The updated version: \d*(\.)?\d+ does not have that issue.
Please note that negative values will not be allowed as \d matches only digits 0..9
^\d*\.?\d*$ should do the trick, but a little thinking and reading more about regex would have told you the same.
Didn't see that . alone or . at the end is not allowed. So ^\d*(\.\d+)?$ sould be just fine