I'm still learning regex and was hoping someone could tell me what this regex does exactly. Thank you.
\d{8,9}0101\d{3}
Breaking it apart:
\d{8,9}
That means either eight or nine digits (0-9).
0101
That means the literal string 0101
\d{3}
That means precisely three number digits.
You can use Expresso to Know more.
Youre regex means
1.Any digit of 8 or 9 repetation
2 then 0101
3 then any digit of exact 3 repetation
I would recommend to start from some source where theory could be found, later on using some tools where you can interactively check how this knowledge can be applied.
http://www.regular-expressions.info/posix.html <- This site contains information about POSIX standard for regular expressions.
Personally for testing matching I use rubular.com, but it references ruby's implementation of regexps. So it also depends on what regexp implementation you use.
In your case it is simple to answer and there should be no difference between different regexp implementations, though.
(A) \d{8,9} - a digit (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) repeated minimum 8 to maximum 9 times
(B) 0101 - literal string 0101
(C) \d{3} - 3 then any digit of exact 3 repetation
regex does = A + B + C
This finds 8 or 9 digits (numbers 0-9), followed by 0101 followed by exactly three digits...
(You should have been able to figure that out by searching!)
Autopsy:
\d{8,9} - a digit (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) repeated 8 to 9 times
0101 - a literal string of the characters 0101
\d{3} - a digit (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) repeated exactly 3 times
Note: repeated doesn't mean "the same character" but anything in the match. That means that "repeated exactly 3 times" for \d could be 111, 123, 989 etc.
Related
I am having trouble crafting a regex. For example, in the string A123 4HEL5P6 789 I want to match all the numbers 4, 5, 6, 7, 8, 9 but not 1, 2, 3.
I have tried using negative look behind with the regex (?<!^\w)\d+ but this matches the numbers in the first word.
Edit: Any numbers in the first continuous sequence of characters should not be matched, the first continuous sequence being from start (^) to a whitespace (\s). In 09B8A HE1LP only 1 should be matched, not 0, 9, or 8, as these digits are in the first word.
If your dialect supports variable-length negative lookbehinds, then this should work:
r = /(?<!^\w*)\d/g
console.log(...'A123 4HEL5P6 789'.match(r))
Otherwise, you could use /^\w*|\d/g and discard the first match.
I am trying to write a regex that can match the following instructions
A sequence of character with the “AT” prefix, followed by “nG” where n is a digit from 1 through 5 and then "G" and lastly followed by a suffix of 5 numeric digits.
Note: just the ordinary regular expression not language specific.
An example of a matching string is this: “AT1G01040”
Here is what I could construct AT[1-5]G(d\{1,5}) but I am not sure if it is the correct answer.
Please, I need your hand on this thanks.
If the number of digits at the end may be from 1 to 5, you may use
^AT[1-5]G[0-9]{1,5}$
See the regex demo.
Note that if the number of digits at the end must be exactly 5, you must remove 1,:
^AT[1-5]G[0-9]{5}$
Details
^ - start of string
AT - a sequence of chars AT
[1-5] - 1, 2, 3, 4 or 5
G - a G char
[0-9]{1,5} - any 1 to 5 consecutive occurrences of an ASCII digit (or - if you use {5} - exactly 5 occurrences)
$ - end of string.
For example, on my cisco switch I want to find all results with a second octet between 63-255.
So first octet 10.
Second octet 64 - 255
Third and fourth octet can be any
So it should like this 10.[64 - 255 ]..
This where I got to
10 \?\ ..* \ ..*
Thanks
The following regex does what you want (mandatory regex101 link):
10\.(6[4-9]|[7-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(1?\d\d?|2[0-4]\d|25[0-5])\.(1?\d\d?|2[0-4]\d|25[0-5])
It may look complex (mostly because of its length), but it's actually straightforward. Here's a breakdown:
10 matches the first octet which is supposed to be 10
\. matches a dot. Same goes for the other \.s
(6[4-9]|[7-9]\d|1\d\d|2[0-4]\d|25[0-5]) matches the second octet, making sure it's between 64 and 255 (inclusive) this way:
Match a 6 followed by a 4, 5, 6, 7, 8 or 9 6[4-9] (numbers between 64 and 69), or
Match a 7, 8 or 9 followed by a digit [7-9]\d (numbers between 70 and 99), or
Match a 1 followed by two digits 1\d\d (numbers between 100 and 199), or
Match a 2 followed by a 0, 1, 2, 3 or 4, which is then followed by a digit 2[0-4]\d (numbers between 200 and 249), or
Match a 2 followed by a 5 followed by a 0, 1, 2, 3, 4 or 5 25[0-5] (numbers between 250 and 255)
The first (1?\d\d?|2[0-4]\d|25[0-5]) matches the third octet (which can be anything between 0 and 255) this way:
Match a digit optionally preceded by a 1 and optionally followed by another digit 1?\d\d? (numbers between 0 and 199), or
Match a 2 followed by a 0, 1, 2, 3 or 4, which is then followed by a digit 2[0-4]\d (numbers between 200 and 249), or
Match a 2 followed by a 5 followed by a 0, 1, 2, 3, 4 or 5 25[0-5] (numbers between 250 and 255)
The second (1?\d\d?|2[0-4]\d|25[0-5]) matches the fourth octet using the same logic
I need regex that contains and have mandatory at least one of each
Uppercase letters -- A, B, C...
Lowercase letters -- a, b, c...
Numbers -- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9...
Special characters -- ` ~ ! # # $ % ^ & *
like aaaaAAA123! or 0987ZZZZZz#
This site surely has similar questions to validate passwords.
But it's still amusing to craft a regex for a particlar case.
The regex below will match strings that contain all 4 character groups.
^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[`~!##$%^&*])[a-zA-Z0-9`~!##$%^&*]+$
The 4 lookaheads garantee that at least 1 character for each character group is available.
could somebody please tell me what the following expressions means:
\d{6,8}
As far as I know it's a regular exp
Between 6 and 8 numeric digits.
(As it's not anchored to boundaries or start & end of string, it would also match between 6 and 8 digits within a longer series of digits - for instance, it will match 123456, 1234567, 1234678, but also the first 8 digits of 123456789.)
\d is a character class - it could also have been written as [0-9]. The {} part is a repetition count; it could be a single number, e.g. {6}, or, as in this case, a range - so the {6,8} means "the previous thing, repeated between 6 and 8 times".
it matches between 6 and 8 sequential numeric digits.
\d is equivalent to the character class [0-9], and the {,} notation specifies an exact number of times that a pattern has to match.
matches a digit that is of length between 6 and 8
it means, at least 6 digits and no more than 8 digits
It means between 6 to 8 numbers in a row.
\d means a number [0-9]
{6, 8} means min. of 6, max. of 8
You use curly braces to describe how many of the previous character you want to look for. Entering a single number, like {3} means 3 in a row. Adding a second number changes this into min/max.
http://www.regular-expressions.info
is the best site on the web for learning about regular expressions.