Can anyone please explain me what this regex signifies?
/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/
I think this regex will validate the IPV4 address
Please use this link to get explation of your regex
Regex Explanation
NODE EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[1-9] any character of: '1' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
[1-9] any character of: '1' to '9'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
1 '1'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
2 '2'
--------------------------------------------------------------------------------
[0-4] any character of: '0' to '4'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
25 '25'
--------------------------------------------------------------------------------
[0-5] any character of: '0' to '5'
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
( group and capture to \2 (3 times):
--------------------------------------------------------------------------------
. any character except \n
--------------------------------------------------------------------------------
( group and capture to \3:
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
[1-9] any character of: '1' to '9'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
1 '1'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
2 '2'
--------------------------------------------------------------------------------
[0-4] any character of: '0' to '4'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
25 '25'
--------------------------------------------------------------------------------
[0-5] any character of: '0' to '5'
--------------------------------------------------------------------------------
) end of \3
--------------------------------------------------------------------------------
){3} end of \2 (NOTE: because you are using a
quantifier on this capture, only the LAST
repetition of the captured pattern will be
stored in \2)
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
While the answer above explains the regex atom by atom, I think the answer that you're looking for is "it matches IPv4 addresses."
To wit:
# Match the beginning of a string
/^
# Match a number from 1-255
([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
# Same as above with a . in front of it
(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))
# Match the above three times.
{3}
# Match end of the string
$/
It is look like an expression which accepts values from 1.0.0.0 to 255.255.255.255
A better explanation :
Meaning
Related
I have a large amount of article on my blog I want to rename and reorganize.
The current structure is this one:
2005_03_19_this_is_the_filename.md
2007_07_23_another_filename.md
2021_01_12_filename.md
And here's what I want to achieve:
2005/03/this_is_the_filename/index.md
2007/07/another_filename/inedx.md
2021/01/filename/index.md
Here's the regex I want to use but I do not know how to execute it.
/(\d{4})_(\d{2})_(\d{2})_(.*).md/gm
substitution: $1/$2/$4/index.md
I'm currently trying to execute it with rename-cli but can't figure out how to write the command.
I manage to it with the following command:
$ rename -p 's~(\d{4})_(\d{2})_\d{2}_(.+)(\.md)$~$1/$2/$3/index.md~' *.md
Thanks to #anubhava
Also use
rename -p 's,([0-9]{4})_([0-9]{2})_[0-9]{2}_(.*)(?=\.md$),$1/$2/$3/index,' *.md
See regex proof
EXPLANATION
NODE EXPLANATION
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[0-9]{4} any character of: '0' to '9' (4 times)
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
_ '_'
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2 times)
--------------------------------------------------------------------------------
) end of \2
--------------------------------------------------------------------------------
_ '_'
--------------------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2 times)
--------------------------------------------------------------------------------
_ '_'
--------------------------------------------------------------------------------
( group and capture to \3:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
) end of \3
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
md 'md'
--------------------------------------------------------------------------------
$ before an optional \n, and the end of
the string
--------------------------------------------------------------------------------
) end of look-ahead
I have this regex which validates IPV4 and IPV6 ip addresses and CIDR but i only want to validate ipv4 addresses and cidr
^(((((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([1-9]|1[0-9]|2[0-8]|3[0-2])){0,1}){0,1})|((((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])){0,1})))((\s*,\s*)(?=[^,])){0,1})+$
someone could help me with this?
Remove the unnecessary:
^(((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([1-9]|1[0-9]|2[0-8]|3[0-2])){0,1}){0,1}((\s*,\s*)(?=[^,])){0,1})+$
See regex proof.
EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
( group and capture to \1 (1 or more times
(matching the most amount possible)):
--------------------------------------------------------------------------------
( group and capture to \2 (between 0 and 1
times (matching the most amount
possible)):
--------------------------------------------------------------------------------
( group and capture to \3 (3 times):
--------------------------------------------------------------------------------
( group and capture to \4:
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
[1-9] any character of: '1' to '9'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
1 '1'
--------------------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2
times)
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
2 '2'
--------------------------------------------------------------------------------
[0-4] any character of: '0' to '4'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
25 '25'
--------------------------------------------------------------------------------
[0-5] any character of: '0' to '5'
--------------------------------------------------------------------------------
) end of \4
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
){3} end of \3 (NOTE: because you are using
a quantifier on this capture, only the
LAST repetition of the captured
pattern will be stored in \3)
--------------------------------------------------------------------------------
( group and capture to \5:
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
[1-9] any character of: '1' to '9'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
1 '1'
--------------------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2
times)
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
2 '2'
--------------------------------------------------------------------------------
[0-4] any character of: '0' to '4'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
25 '25'
--------------------------------------------------------------------------------
[0-5] any character of: '0' to '5'
--------------------------------------------------------------------------------
) end of \5
--------------------------------------------------------------------------------
( group and capture to \6 (between 0 and
1 times (matching the most amount
possible)):
--------------------------------------------------------------------------------
\/ '/'
--------------------------------------------------------------------------------
( group and capture to \7:
--------------------------------------------------------------------------------
[1-9] any character of: '1' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
1 '1'
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
2 '2'
--------------------------------------------------------------------------------
[0-8] any character of: '0' to '8'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
3 '3'
--------------------------------------------------------------------------------
[0-2] any character of: '0' to '2'
--------------------------------------------------------------------------------
) end of \7
--------------------------------------------------------------------------------
){0,1} end of \6 (NOTE: because you are using
a quantifier on this capture, only the
LAST repetition of the captured
pattern will be stored in \6)
--------------------------------------------------------------------------------
){0,1} end of \2 (NOTE: because you are using a
quantifier on this capture, only the
LAST repetition of the captured pattern
will be stored in \2)
--------------------------------------------------------------------------------
( group and capture to \8 (between 0 and 1
times (matching the most amount
possible)):
--------------------------------------------------------------------------------
( group and capture to \9:
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ")
(0 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
, ','
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ")
(0 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
) end of \9
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
[^,] any character except: ','
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
){0,1} end of \8 (NOTE: because you are using a
quantifier on this capture, only the
LAST repetition of the captured pattern
will be stored in \8)
--------------------------------------------------------------------------------
)+ end of \1 (NOTE: because you are using a
quantifier on this capture, only the LAST
repetition of the captured pattern will be
stored in \1)
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
I've got the below which is for a Git push rule, it works fine with the below example:
^(fix|feature|wip|dev-task|release)\/([a-zA-Z]+)\-\d+\-(\w+\-*)*
feature/ab-1234-fix
How can enforce uppercase letters ONLY for the AB? This will only ever be 2 characters.
feature/AB-1234-fix
Use
^(fix|feature|wip|dev-task|release)\/(AB|a[^b]|[^a]b|[a-zA-Z]|[a-zA-Z]{3,})\-\d+\-(\w+\-*)*
See proof.
EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
fix 'fix'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
feature 'feature'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
wip 'wip'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
dev-task 'dev-task'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
release 'release'
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
\/ '/'
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
AB 'AB'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
a 'a'
--------------------------------------------------------------------------------
[^b] any character except: 'b'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
[^a] any character except: 'a'
--------------------------------------------------------------------------------
b 'b'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
[a-zA-Z] any character of: 'a' to 'z', 'A' to 'Z'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
[a-zA-Z]{3,} any character of: 'a' to 'z', 'A' to 'Z'
(at least 3 times (matching the most
amount possible))
--------------------------------------------------------------------------------
) end of \2
--------------------------------------------------------------------------------
\- '-'
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
\- '-'
--------------------------------------------------------------------------------
( group and capture to \3 (0 or more times
(matching the most amount possible)):
--------------------------------------------------------------------------------
\w+ word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\-* '-' (0 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
)* end of \3 (NOTE: because you are using a
quantifier on this capture, only the LAST
repetition of the captured pattern will be
stored in \3)
The department number is either 5 digits, first digit has to be non-zero, or six digits, with a period and a 0 or 1 following.
So, first example would be 10000, 50050, 99999.
Second, 992000.1, 950000.0.
This is a simple "mask", so no coding is available in the GUI / native format.
Currently, I had [1-9]{1}[0-9]{0,4} for the first option
Use
\b(?:[1-9][0-9]{4}|[0-9]{6}\.[01])\b
See proof.
Explanation
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
--------------------------------------------------------------------------------
(?: group, but do not capture:
--------------------------------------------------------------------------------
[1-9] any character of: '1' to '9'
--------------------------------------------------------------------------------
[0-9]{4} any character of: '0' to '9' (4 times)
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
[0-9]{6} any character of: '0' to '9' (6 times)
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
[01] any character of: '0', '1'
--------------------------------------------------------------------------------
) end of grouping
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
What is the REGEX to accept a string like this
Starts with EDO
has many characters(words,numbers,hypehns) in between
does not contain 24 or |(pipe)
Example:
Should match
edo-<<characters>>-<<characeters>>-<<numbers>>
BUT NOT
edo-<<characters>>-<<characeters>>-<<numbers>> | <<characeters>>- <<characeters>>- <<numbers>>
The string does not have a constant length
The negative look ahead will help you to decide if the string doesnt contain 24 or |
The regex can be written as
/^edo(?!.*(24|\|))[-a-zA-Z0-9]+$/i
Regex Demo
How it matches
^ Anchors the regex at the start of the string
edo The anchor ensures that the string starts with edo
(?!.*(24|\|)) look ahead assertion. It checks if the string doesnt contain 24 or |. If it doesnt contain, then proceeds with the remaining pattern. If it contains, discards the match
[-a-zA-Z0-9]+ Matches numbers alphabets or -
$ anchors the regex at the end of the string.
^EDO(?!.*(?:(?<!\d)24(?!\d)|\|))[a-zA-Z0-9 -]+$
Try this.This should work.Use flag gmi.
See demo.
https://regex101.com/r/fA6wE2/37
NODE EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
EDO 'EDO'
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
(?: group, but do not capture:
--------------------------------------------------------------------------------
(?<! look behind to see if there is not:
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
) end of look-behind
--------------------------------------------------------------------------------
24 '24'
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
) end of look-ahead
| OR
--------------------------------------------------------------------------------
\| '|'
--------------------------------------------------------------------------------
) end of grouping
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
[a-zA-Z0-9-]+ any character of: 'a' to 'z', 'A' to 'Z',
'0' to '9', '-' (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string