Skip to content

Instantly share code, notes, and snippets.

@taichi
Created January 14, 2011 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taichi/779326 to your computer and use it in GitHub Desktop.
Save taichi/779326 to your computer and use it in GitHub Desktop.
(
((?=(?>.*?::)(?!.*::)))
(::)?
([0-9a-f]{1,4}::?){0,5}|([0-9a-f]{1,4}:){6}
)
(
\2([0-9a-f]{1,4}(::?|$)){0,2}
|(
(25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9])(\.|$)
){4}
|[0-9a-f]{1,4}:[0-9a-f]{1,4}
)
(?<![^:]:)
(?<!\.)
static void r2() {
String s = "(((?=(?>.*?::)(?!.*::)))(::)?([a]{1,3}::?){0,5}|([a]{4}:){6})";
Pattern p = Pattern.compile(s);
String[] datas = { "a:a::", "::a:a:", "a::a:",
"::aaa:aaa:aaa:aaa:aaa:", "::aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:" };
for (String data : datas) {
Matcher m = p.matcher(data);
while (m.find()) {
for (int i = 0; i <= m.groupCount(); i++) {
System.out.printf("%s [%s]\n", i, m.group(i));
}
}
System.out.println("######");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment