Regular [removed]RegEx) for IPv6 Separate from IPv4

前端 未结 3 1642
孤独总比滥情好
孤独总比滥情好 2020-12-07 00:16

Please read before marking as duplicate

I have not been able to create or find a RegEx that works for all IPv6 formats (my test cases are b

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 00:40

    :: is a valid IPv6 address (the all-zeroes address), so why not accept it?

    And if you don't want to accepts IPv6 addresses with the last 32 bits written in IPv4 notation (why wouldn't you, they are valid address representations) then just revoke the last part of the regex that deals with them (starting with ::(ffff).

    Anyway, the regex does indeed contain a few errors in the IPv4-notation part. The IPv4 notation is just a different way to write the last 32 bits of the IPv6 address, and the regex doesn't handle all valid variants of that. Besides, it even forgets to escape the . so it will also accept many invalid strings.

提交回复
热议问题