• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Validating IPv6 url using regex

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Saloon Keeper
Posts: 7175
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7175
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(blush) Doffing my hat, I stand corrected.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for entertainment :-). I fixed it.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Siddhesh Deodhar wrote:Thanks for entertainment :-). I fixed it.



Could you please post the fix
 
Marshal
Posts: 74378
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I am afraid the OP hasn't posted anything for the best part of four years, so you may not get a reply. Sorry.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic