This question already has an answer here:
Regex to validate password
(1 answer)
Closed 9 years ago.
I'm trying to develop a regular expression for validating a password which should meet following criteria
should have at least one Uppercase letter,
should have at least one Lowercase letter,
should have at least one Special character,
should have at least one digit,
must be minimum 6 characters long.
I have developed a expression for that:
password_pattern=/^(?=.*[0-9]) (?=.*[!##$%^&*]) (?=.*[a-z]) (?=.*[A-Z]) {6} $/
However it is not working as I intended. What am I going wrong?
I'm new to regular expressions, so I'd appreciate an explanation rather than a 'use this' sort of answer, please explain.
You are missing a single dot before the {6}, and you've added spaces, which you shouldn't have:
password_pattern=/^(?=.*[0-9])(?=.*[!##$%^&*])(?=.*[a-z])(?=.*[A-Z]).{6}$/
Related
This question already has answers here:
How to make regex match only first occurrence of each match?
(4 answers)
Closed last year.
I have looked all over for an answer to this, but no one has had quite the same question as I do.
The problem I am trying to solve is to find the first capital letter in a string and no other capital letters. I have been able to narrow my search to each instance of a capital letter, but no amount of quantifiers I could find can make it only the first one.
For example, in this String abcDefgH. I only want to match the D and not the H.
Use a simple
([A-Z])I maybe missunderstood your question, but this will select only the first Capitalized letter in string.
This question already has answers here:
Regular expression to match a dot
(7 answers)
Closed 2 years ago.
I'm currently working with the regex to only allow users to input digits xxxx.xxx or xxxx.xx or xxxx.
I tried the below code but instead of allowing the 5 digits, it also allows 7 and 8 digits.
(^\d{5}$)|(^\d{4}.\d{2}$|^\d{4}.\d{3}$)
^[0-9]{4}.([0-9]{3}|[0-9]{2}|[0-9]{5})$
Sample output: 1223.345 or 1324.23 or 23564
Advance Thanks!
Your period needs to be escaped, or else it will be the "any character" symbol, and will allow a digit in that place. So for that part of your regex, try:
/^\d{5}$|^\d{4}\.\d{2}$|^\d{4}\.\d{3}$/;
I'm not sure what the remainder of your regex is for, but seems outside the scope of what you're asking.
This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 3 years ago.
Regex testing for special characters, decimal except for hyphen, commas, alpha-numeric.
Attempt
^(\+|-)?([0-9]+)$/
I'm trying to write a regex to match special characters, decimal except for commas, a hyphen, alpha-numeric.
Welcome!
Maybe, you might just want to list the chars that you wish in a [] and test it. Maybe, a simple expression like this would be desired for you and you could work on it:
^([?!"'~&%$*##0-^#9]+)$
You might want to use this tool and design an expression that you wish, then test it with real samples and maybe change it as you wish.
You can also use an online visualizer to view how your expression would work:
This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 5 years ago.
I've tried to make a regular expression that match anything except if contains a 11 digits like 12345678910 so don't match anything
what i have tried
[^\d{11}]
but {11} doesn't work with \d expression
so what i have to do ?
you can use the regex
^(?!.*\d{11}).*$
see the regex101 demo
It's not a very good task for regex to solve actually, because you have to describe every string that doesn't contain 11 consecutive digits.
If possible, I suggest matching a string that does contain 11 consecutive digits, then inverting the success of that match with the language or tool from which you execute this regex.
Depending on your regex flavour, you might also be able to use a negative lookahead such as presented in other answers.
This seemed to work for me using a negative look around:
/^((?!\d{11}).)*$/gm
This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
Closed 5 years ago.
Here is my regex that tries to match a valid URL:
^(https?:\/\/((\b\w[^-][a-zA-Z0-9-]{1,33})\.){1,34}([[a-zA-Z0-9]{1,6})\/?)$
and I've tried to find way to make a simple solution to forbid the use of a hyphen '-' in the beginning and end of a group of letters and numbers.
I'd tried to use \b\w[^-]. But it hasn't helped.
For example, my regex matches this string, but it shouldn't
http://example-.com
I found an answer by myself
^(https?:\/\/([WWW\.]|[www\.])?((([a-zA-Z0-9]|[a-zA-Z0-9][-][a-zA-Z0-9]){1,10})\.){1,33}([[a-zA-Z0-9]{1,6})\/?)$
its just a simple OR [a-zA-Z0-9]|[a-zA-Z0-9][-][a-zA-Z0-9]
If you'll find better solution pls send it :)