Ted North wrote:
My question pertains to the regex String reference that contains the mammoth regular expression. Could someone please help me understand this some more? This is a really useful program but am pretty confused about what exactly is going on.
Ted North wrote:
So with the OR symbols () is the expression saying find a number like 250255 OR 2024 OR 0 or 1?
Ted North wrote:This is what I have so far. Still I am surprisingly confused about what is going on in this regular expression.
Henry Wong wrote:For large regexes, it is generally a good idea to break it down to it's components.
Rico Felix wrote:
Henry Wong wrote:For large regexes, it is generally a good idea to break it down to it's components.
That is exactly what you must do to make sense of long regex's...
We start with "\\b((25[05]2[04]\\d[01]?\\d\\d?)(\\.)){3}(25[05]2[04]\\d[01]?\\d\\d?)\\b" and move left to right just like the regex engine would:
Seeing that you have a fair amount of knowledge on regex's from your last post (the image), skipping over the obvious parts we decipher through the nonobvious
25[05] translates to 250 min to 255 max
2[04]\\d translates to 200 min to 249 max
[01]?\\d\\d? translates to 0 min to 199 max (remember ? mean 0 or one)
Ted North wrote:What is the operator that determines if three numbers appear, two numbers, or just one since an IP could be 192.168.300.300 or 192.168.1.1 etc?
Rico Felix wrote:
Ted North wrote:What is the operator that determines if three numbers appear, two numbers, or just one since an IP could be 192.168.300.300 or 192.168.1.1 etc?
[01]?\\d\\d? is used to get one digit or two digits or three digits since two digits are optional...
Ted North wrote:So with the ORs   the expression can choose only one of these? So in this case it would either be a number starting with 25 or 2 or 0 or 1?
Ted North wrote:Also, when would the regex engine choose the zero in [01] towards the end of the regex? I have never seen an IP such as 192.168.1.01
Ted North wrote:Also, when would the regex engine choose the zero in [01] towards the end of the regex? I have never seen an IP such as 192.168.1.01
Steve
Rico Felix wrote:
Ted North wrote:What is the operator that determines if three numbers appear, two numbers, or just one since an IP could be 192.168.300.300 or 192.168.1.1 etc?
[01]?\\d\\d? is used to get one digit or two digits or three digits since two digits are optional...
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Free, earth friendly heat  from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/freeheat
