Using regex to restrict user input [duplicate] - regex

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

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');

Regex Extract on Google Sheets [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I am trying to find an expression that can be used extract a string after a specific number of characters.
E.g
FR_EN_BR_Student_Exact
FR_EN_NB_Student_Exact
I would want a pattern that can take all characters past the second underscore ( not including the underscore.
Would appreciate any ideas!
I understand basic regex but am having trouble with this specific query.
try:
=ARRAYFORMULA(IFNA(REGEXEXTRACT(A1:A, ".+_.+_(.+_.+_.+)")))

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$

Use regular expressions to select valid email address [duplicate]

This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 6 years ago.
I came up with the following
([\w.%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4})
I would also like to remove emails that start with a number or -. By remove I mean to select only the address and not to remove the entire match.
Is there a way to do that?
^(?:\d+|-+)?([\w.%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4})$
This should do the trick. It'll capture emails but also filter out ones that start with a number or the - character and pulls the email from it.

creating a regex that captures these rules [duplicate]

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.