Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:31:27+00:00 2026-06-18T03:31:27+00:00

I have a regular expression for IPv6 addresses as given below IPV4ADDRESS [ \t]*(([[:digit:]]{1,3}.){3}([[:digit:]]{1,3}))[

  • 0

I have a regular expression for IPv6 addresses as given below

IPV4ADDRESS      [ \t]*(([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3}))[ \t]*
x4               ([[:xdigit:]]{1,4})
xseq             ({x4}(:{x4}){0,7})
xpart            ({xseq}|({xseq}::({xseq}?))|::{xseq})
IPV6ADDRESS      [ \t]*({xpart}(":"{IPV4ADDRESS})?)[ \t]*

It is correctly all formats of IPv6 addresses including

1) non-compressed IPv6 addresses
2) compressed IPv6 addresses
3) IPv6 addresses in legacy formats.(supporting IPv4)

Ideal examples of IPv6 addresses in legacy formats would be

2001:1234::3210:5.6.7.8

     OR
2001:1234:1234:5432:4578:5678:5.6.7.8

As you can see above there are 10 groups separated by either `":" or ".".`

As opposed to 8 groups in normal IPv6 addresses.This is because the last 4 groups that are separated by `”.” should be compressed into least significant 32-bits of the IPv6 addresses.Hence we need 10 groups to satisfy 128 bits.

However If I use the following address format

   2001:1234:4563:3210:5.6.7.8

Here each group separated by “:” represents 16-bits.the last four groups separted by “.” represents 8 bits.Total number of bits is 64 + 32 = 96 bits.32 bits are missing

The regular expression is accepting it as a valid IPv6 address format.I am unable to figure out how to fix the regular expression to discard such values.Any help is highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:31:29+00:00Added an answer on June 18, 2026 at 3:31 am

    Here’s the grammar for IPv6 addresses as given in RFC 3986 and subsequently affirmed in RFC 5954:

     IPv6address   =                             6( h16 ":" ) ls32
                    /                       "::" 5( h16 ":" ) ls32
                    / [               h16 ] "::" 4( h16 ":" ) ls32
                    / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
                    / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
                    / [ *3( h16 ":" ) h16 ] "::"    h16 ":"   ls32
                    / [ *4( h16 ":" ) h16 ] "::"              ls32
                    / [ *5( h16 ":" ) h16 ] "::"              h16
                    / [ *6( h16 ":" ) h16 ] "::"
    
     h16           = 1*4HEXDIG
     ls32          = ( h16 ":" h16 ) / IPv4address
     IPv4address   = dec-octet "." dec-octet "." dec-octet "." dec-octet
     dec-octet     = DIGIT                 ; 0-9
                    / %x31-39 DIGIT         ; 10-99
                    / "1" 2DIGIT            ; 100-199
                    / "2" %x30-34 DIGIT     ; 200-249
                    / "25" %x30-35          ; 250-255
    

    Using this, we can build a standards-compliant regular expression for IPv6 addresses.

    dec_octet      ([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])
    ipv4address    ({dec_octet}"."){3}{dec_octet}
    h16            ([[:xdigit:]]{1,4})
    ls32           ({h16}:{h16}|{ipv4address})
    ipv6address    (({h16}:){6}{ls32}|::({h16}:){5}{ls32}|({h16})?::({h16}:){4}{ls32}|(({h16}:){0,1}{h16})?::({h16}:){3}{ls32}|(({h16}:){0,2}{h16})?::({h16}:){2}{ls32}|(({h16}:){0,3}{h16})?::{h16}:{ls32}|(({h16}:){0,4}{h16})?::{ls32}|(({h16}:){0,5}{h16})?::{h16}|(({h16}:){0,6}{h16})?::)
    

    Disclaimer: untested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this regular expression, I would like it to remove all text between
I have a pattern that is given below to match an ipv6 address in
I have a regular expression below that works for a string example like: MCCOY
I have a regular expression to validate the dates and it works fine, this
I have a regular expression which allows the value range '1111' - '999999', excluding
I have a regular expression which uses GroupCollection s in it's capture to capture
I have a regular expression to validate a input value. At this point I
I have a regular expression to match anything between { and } in my
I have this Regular Expression that matches the following strings: <!-- 09-02-2009 ---> <!--
i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.