What does regular expression [A-Z]{2,3}\\d+ mean [duplicate] - regex

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
What does the regex [A-Z]{0,2,3}\\d+ mean?
Does it match strings like
AAA1234
0000123
AA12345
Thanks

[A-Z]{0,2,3}\\d+
That looks like a typo.
{} braces shouldn't have more than two numbers in it.
[A-Z]{0,3} mean any alphabet between A and Z (capital) can occur 0 to 3 times.
And \d+ means any digit (0-9) can occur 1 or more times.
That is the reason [A-Z]{0,3}\d+ matches AAA1234, 0000123 and AA12345

Your regex ([A-Z]{2,3}\\d+) will match
Two or three letters A-Z,
followed by a backslash "\",
and finally one or more instances of the letter "d".

Related

Doesn't the Quantifier {0,0} mean to exclude character in regex? [duplicate]

This question already has answers here:
Reference - What does this regex mean?
(1 answer)
What do comma separated numbers in curly braces at the end of a regex mean?
(6 answers)
Closed 5 years ago.
What i have understood about the Quantifier {}:
The first integer in Quantifier {} means at least and the second integer means at most. So {n,m} would mean at least n and at most m.
What i don't understand:
Similarly, {0,0} means at least zero and at most zero (which is equal to excluding some character). So the Regex /(?=\W{0,0})/ should exclude special characters but it doesn't why ?
Because "exactly 0 occurrences of [anything]" is satisfied by an empty string... which of course is before and after each character, making it useless for look-aheads and look-behinds

Regular Expression.how to add optional character at end of regex [duplicate]

This question already has answers here:
Regex how to match an optional character
(5 answers)
Closed 6 years ago.
I just want to write a regular expression 4 digits and '.' and 5 digits and optional 'A'
Ex: 1111.2345A where A is optional.
^[0-9]{4}[\.][0-9]{4}$
This reg ex will give 1111.2345, but how to add Optional 'N' at last.
Use ? at the end for characters:
[A-Za-z]?
This will match at most 1 presence of a character (lower or upper case).
You can check for a character zero or one times with this:
'[A]{0,1}'
Put that at the end of your string and it will try and match the character 'A' zero or one times. You may also use the symbol ? to match zero or one times. All about preference.
To get a single, optional A at the end, append A? to your regular expression:
^[0-9]{4}[\.][0-9]{4}A?$
Btw. instead of [0-9] you could use \d which stands for 'digit':
^\d{4}\.\d{4}A?$

Regular expression to restrict number of digits in a string [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I need to have a regular expression to restrict the number of digits in a string which may contain alphabets or any other characters along with digits. Is this possible with regular expressions ?
The idea is to anchor beginning and end of string and allow exactly n repetitions of a digit with something else. For example, exactly 6 digits in a string:
^\D*(\d\D*){6}$

noncapturing group explanation within a positive lookahead [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 5 years ago.
Does this regular expression mean that at least one of the following that isn't a-z:
(?=.*(?:[a-z]))
It's part of the following expression:
/^(?=[A-Za-z0-9\'\s\d\.]{2,50}$)(?=.*(?:[a-z]))[a-zA-Z0-9]+[A-Za-z0-9\'\s\.]+$/m
No, (?=.*(?:[a-z])) means that there could be whatever but must finish with a lowercase letter.
This regex means:
/^(?=[A-Za-z0-9\'\s\d\.]{2,50}$)(?=.*(?:[a-z]))[a-zA-Z0-9]+[A-Za-z0-9\'\s\.]+$/m
Match the line that starts with 2 to 50 alphanumeric, single quote, spaces or a dot, and then follows with lower case letter, and continues with alphanumerics and must ends followed by alphanumerics, spaces, single quote or dot.
Here you can see a better graphical approach for your regex:
Actually, this can be improved as:
/^(?=[A-Za-z\d'\s.]{2,50}$)(?=.*[a-z])[a-zA-Z\d]+[A-Za-z\d'\s.]+$/m

Meaning of \d{1-3 }in regular expression [duplicate]

This question already has answers here:
Reference - What does this regex mean?
(1 answer)
Using explicitly numbered repetition instead of question mark, star and plus
(4 answers)
Closed 3 years ago.
I've been searching for a long time but didn't find an answer for my question, can tell me what the meaning of
(?:[-\w\d{1-3}]+\.)+
and not
(?:[-\w\d{1,3}]+\.)+
I don't understand the {1-3} part and can't find anywhere what it's mean.
Thank you
Everything between [] are characters to be matched. So it matches each of those characters:
- the literal character -
\w match any word character [a-zA-Z0-9_]
\d match a digit [0-9]
{ the literal character {
1-3 a single character in the range between 1 and 3
} the literal character }
the 1-3 makes no sense there, as well as the \d. Both are included in \w
Even what you would say that is correct {1,3} inside the [] makes no sense.