• Post Reply Bookmark Topic Watch Topic
  • New Topic

Validating IPv6 url using regex  RSS feed

 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I have regular expression to find out valid url inside a text. its like follows
http://|https://|ftp://|ftps://|news:|www.)[^\"\'\\(\\)\\[\\{\\}\\<[:space:]]*

This works fine for all valid URL's. i.e. if URL in text is say" http://10.44.5.7:8080/abc/xyz[ooo" then valid url will be
"http://10.44.5.7:8080/abc/xyz"

Now I have requirement where IPv6 addressed URL of format "http://[address]:port" I need to handle.
I change the regular expression as follows

http://|https://|ftp://|ftps://|news:|www.)[\\[]*[^\"\'\\(\\)\\[\\{\\}\\<[:space:]]*

i.e. added "[\\[]*" between valid characters and invalid characters.

Is there any better fix then this ?
 
Tim Moores
Saloon Keeper
Posts: 4032
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not an IP6 address, that's merely an IP4 address with an appended port number. I don't think there are any browsers out there yet that can handle IP6 URLs.

So you have an optional additional part after the server name, consisting of a colon and 1 to 5 digits. What comes to mind?

Update: Rereading your post I'm confused - the square brackets should be part of the URL? That's not valid in either IP4 or IP6.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:Update: Rereading your post I'm confused - the square brackets should be part of the URL? That's not valid in either IP4 or IP6.

Actually it is. If an IPV6 address has a port number appended to it in a URL, then the address itself has to be wrapped in []. This is because IPV6 addresses have variable numbers of colons in them, so there is no way to tell if the last number is part of the address or a port number
So if your IP6 address is 2002:8277:2f9c::8277:2f9c and your port number is 8080, then a URL would have to contain [2002:8277:2f9c::8277:2f9c]:8080
 
Tim Moores
Saloon Keeper
Posts: 4032
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(blush) Doffing my hat, I stand corrected.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like it when men stand for me. I'm such an old fashioned gal.
 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for entertainment :-). I fixed it.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!