I don't remember exactly the syntax since I haven't been mudding in a while. I think you're using a different kind of regex (I use PCRE) but what I'd do is:
pattern: ^dm( *)(\w*)$
First capturing group finds the space after dm. * quantifier allows 0 spaces to unlimited spaces.
Second capturing group finds the name after the space. * quantifier allows 0 letters to unlimited letters.
So when you do 'dm' it correctly matches the pattern, with both capturing groups getting empty strings.
If you do 'dm shapa' for example it will have 'shapa' in the second capturing group. So just send c dispel magic on the correct match for 'shapa'.
If you do 'dm' then your code should have an IF to catch the case of empty strings in the two captured groups. IF first capturing group == '' for example, or IF length(first capturing group) == 0, or something like that. Then it should send c dispel magic.