Strip all dashes and convert to uppercase first. Now you have a clean string of alphanumeric characters.
The trick is figuring out the first group size. If len % k != 0, the first group has len % k characters. Otherwise, the first group has k characters like every other group.
Build the result by taking the first group, then appending a dash followed by k characters for each remaining group. You can also process from right to left and reverse at the end.