>
> 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. 


Using the 0-255 regex of last post you can build a more complex regex.

Because I never worked with IP addresses I consulted Wikipedia to 
understand ranges  IPv4, private network addresses 
<https://en.wikipedia.org/wiki/Private_network#Private_IPv4_addresses>.

*IPv4, private network: 192.168.0.0 – 192.168.255.255*

*(\b192\.168(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b){2})*

I'll explain this one. The others should then be readable.

*( *= open capture group 1
*\b *= word boundary
198 literal
*\. *= escape for literal stop-mark (otherwise *"."* matches  any character)
168 literal
*( *= open capture group 2
*\. *= literal stop-mark
*( *= open capture group 3
*[0-9] etc.* = regex we made in last post to match 0-255
*) *= close capture group 3
*\b *= word boundary
*) *= close capture group 2
*{2}* = repeat pattern in group 2 twice
*) *= close capture group 1

*IPv4, private network: 10.0.0.0 – 10.255.255.255*
*(\b10(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b){3})*

Much like previous, notice *{3}.*

*IPv4, private network: 172.16.0.0 – 172.31.255.255*

*(\b172\.(1[6-9]|2[0-9]|3[01])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b){2})*

This is a bit more complex as it needs 2 ranges. *16-31* and *0-255*. N
otice *{3}.*

*IPv4 private networks starting: 10, 192.168, 172.16*

*(\b(192\.168|10|172\.(1[6-9]|2[0-9]|3[01]))(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b){2,3})*

This combines the three above into one regex. More advanced, but gives idea 
you can combine things. Notice* {2,3}.*

Test for this more complex one
*-> ... is match*

_Should NOT match_↩︎
9.255.255.255↩︎
10.0.0.00↩︎
147.168.255.255↩︎
172.32.255.255↩︎
172.14.255.255↩︎
192.168.1.256↩︎
192.27.255.255↩︎
↩︎
_Should match_↩︎
->10.0.0.0↩︎
->172.16.89.125↩︎
->192.168.1.1↩︎
->192.168.1.255↩︎


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/5e274db2-e816-4f1c-ba85-bed4c5ccd6b5%40googlegroups.com.

Reply via email to