TonyM wrote:
>
> ... check for 10.*.*.* 192.168.*.* 127.*.*.* or if equal to 1.1.1.1 or
> 0.0.0.0. to determine if they are local or public addresses.
>
I done this in two posts so its easier to understand.
To help Mohammad document let's first deal with how to simply match IP
sub-numbers 0 to 255 using regex in decimal & binary.
*0-255, Decimal*
<option value="\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b">0-255
Decimal, no leading zeros</option>
*\b* = "word boundary". (In regex, numbers are just word characters.)
*"(...)"* = a capturing group.
*"|"* = alternate matches within the group (like "or")
*[0-9]* = match from 0 to 9
*[1-9][0-9]* = 10 to 99
*1[0-9][0-9]* = 100 to 199
*2[0-4][0-9]* = 200 to 249
*25[0-5]* = 250 to 255
*\b *= "word boundary"
*00000000-11111111, Binary*
IP addresses, in binary, use leading zeros. These are very easy to match.
255 decimal is 11111111 binary, so just repeat 1 or 0 8 times by using {8} next
to the class or group.
Using* [...] *Character Class
<option value="\b[01]{8}\b">00000000-11111111, Binary Byte</option>
Using* "|" *Alternation in a Capture Group
<option value="\b(0|1){8}\b">00000000-11111111, Binary Byte</option>
*Interesting fact: This is the maximum info a byte (8 bits) can hold, in
decimal 255 & 0, i.e. 256 combinations, hence "magic number" 256.*
TT
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/6e312779-b824-44d0-93f8-8784d33f56af%40googlegroups.com.