Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code> private static IEnumerable&lt;string&gt; Parse(string input) { const string partPattern = @"([A-Fa-f0-9]{1,4})"; string longPattern = string.Format(@"{0} (?:\:{0})*", partPattern); //Group 1 -&gt; 2 string compactPattern = string.Format(@"{0} (?:\:{0})* \:\: {0} (?:\:{0})*", partPattern, RegexOptions.IgnorePatternWhitespace); //Groups 3 -&gt;6 string completePattern = string.Format(@"^{0}$ | ^{1}$", longPattern, compactPattern); var match = Regex.Match(input, completePattern, RegexOptions.IgnorePatternWhitespace); if (match.Success) { if (match.Groups[1].Success) { yield return match.Groups[1].Value.PadLeft(4, '0'); for (int i = 0; i &lt; match.Groups[2].Captures.Count; ++i) yield return match.Groups[2].Captures[i].Value.PadLeft(4, '0'); } else { var count = 6 - match.Groups[4].Captures.Count - match.Groups[6].Captures.Count; //First part yield return match.Groups[3].Value.PadLeft(4, '0'); for (int i = 0; i &lt; match.Groups[4].Captures.Count; ++i) yield return match.Groups[4].Captures[i].Value.PadLeft(4, '0'); //:: block for (int i = 0; i &lt; count; ++i) yield return "0000"; //Second part yield return match.Groups[5].Value.PadLeft(4, '0'); for (int i = 0; i &lt; match.Groups[6].Captures.Count; ++i) yield return match.Groups[6].Captures[i].Value.PadLeft(4, '0'); } } else throw new Exception("No match"); } </code></pre> <p>Something like this should work. The basic idea is just to split the case of the address containing :: and the rest into two different patterns. I used the assumption that :: can never be at the beginning or end so if that doesn't hold you'll have to modify the patterns a bit.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload