regexp don't match if contain specific digit length [duplicate] - regex

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

Related

Regex with exactly one space and special characters [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
Unfortunately I found that the existing examples are confusing and not similar enough to what I am trying to achieve. I need a regular expression to find occurencies of strings like
=> Test[a]
where between the special character > and Test there is exactly one space. The word Test can be replaced by any alphabetic string (=> Apple[b] is another example). I have worked out a regex for all except the first part with the block =>.
Can anyone help me?
I managed to find this expression
.(=>) [a-zA-Z]+\[a\]\.
and it works! Thanks everyone.
Try use this regex:
=> \S+
Here Is Demo

RegEx for special characters and decimals except for commas [duplicate]

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:

Finding a group match part of another group in a regex [duplicate]

This question already has answers here:
How to use regex to find all overlapping matches
(5 answers)
Closed 5 years ago.
I was just wondering how to match a group which has characters already in another group.
If we take this string for example: "aba" and want to match every group of (ab) or (ba).
Obviously (ab|ba) would work, my only problem with that is it only catches one group which is aba but i also want to capture aba, do I have to use a more complex regex for this case?
You can easily achieve this using this regex
(?=(ab|ba))
It will match all the occurrences of both 'ba' and 'ab' even the overlap ones.

Matching first occurrence? [duplicate]

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Regular expression to stop at first match
(9 answers)
Closed 3 years ago.
I know this question has been asked many times, but when I attempted to use the accepted answer that I found here, it does not work, so I assume I'm missing something.
I was attempting to match the Mrs. in the string Rothschild, Mrs. Martin (Elizabeth L. Barrett) using this regular express:
.*, (.*\.).*
But this does not work because of the L.. I then attempted to add the ? a number of different ways, but it still matches all the way to L.. Some things I tried:
.*, (.*\.?).*
.*, (.*\.*?).*
.*, (.*\.+?).*
.*, (.*\.??).*
But none of these work. Can anyone see what I am missing here?
Regex Fiddle
Put ? after the * which was present inside the capturing group. .* is greedy and eats up characters as many as possible. You need to add a quantifier ? after the * to do a shortest possible match.
.*, (.*?\.).*
DEMO

Regex expression for password validation [duplicate]

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}$/