Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ColdFusion regex以正确格式化ipv6地址_Coldfusion_Coldfusion 11 - Fatal编程技术网

ColdFusion regex以正确格式化ipv6地址

ColdFusion regex以正确格式化ipv6地址,coldfusion,coldfusion-11,Coldfusion,Coldfusion 11,尽管有这样的例子,但其中很多都涉及删除前导零或将“0:0:”序列组合成“:”。我看到的大多数例子都是针对其他语言的 以下是我用于压缩/格式化ipv6地址的函数: <cffunction name="formatIPv6" returntype="string" output="yes" access="public" hint="returns a compressed ipv6 address"> <cfargument name="vcIPv6" type="str

尽管有这样的例子,但其中很多都涉及删除前导零或将“0:0:”序列组合成“:”。我看到的大多数例子都是针对其他语言的

以下是我用于压缩/格式化ipv6地址的函数:

<cffunction name="formatIPv6" returntype="string" output="yes" access="public" hint="returns a compressed ipv6 address">
    <cfargument name="vcIPv6" type="string" required="yes" hint="IPv6 address">

    <!--- inside reReplace removes leading zeros, outside reReplace removes repeating ":" and "0:" --->
    <cfreturn reReplace(reReplace(LCase(arguments.vcIPv6), "(:|^)(0{0,3})([1-9a-f]*)", "\1\3", "all"), "(^|:)[0|:]+:", "::", "all")>
</cffunction>
我的问题是两个reReplace()函数是否可以替换为一个reReplace()

如果有更好的方法,我愿意接受建议

formatIPv6(vcIPv6 = "0:0:0:0:0:0:0:1") = ::1 (expected value = ::1)
formatIPv6(vcIPv6 = "0000:0000:0000:0000:0000:0000:0000:0001") = ::1 (expected value = ::1)
formatIPv6(vcIPv6 = "1000:0:0:0:8:800:000c:417a") = 1000::8:800:c:417a (expected value = 1000::8:800:c:417a)
formatIPv6(vcIPv6 = "1080:0:0:0:8:800:200C:417A") = 1080::8:800:200c:417a (expected value = 1080::8:800:200c:417a)
formatIPv6(vcIPv6 = "2001:db8:a0b:12f0:0:0:0:1") = 2001:db8:a0b:12f0::1 (expected value = 2001:db8:a0b:12f0::1)
formatIPv6(vcIPv6 = "fe80:0:0:0:204:61ff:fe9d:f156") = fe80::204:61ff:fe9d:f156 (expected value = fe80::204:61ff:fe9d:f156)