If you're actually doing your own calls to the UnitName API function you shouldn't actually need to do anything as the (*) does not come from that function but is rather added by your unit frames addon. In that case, all you need to use is
If you did however have a situation where you have a string with the (*) in it, I'd do something like this: (as a general function here which may not be what your addon actually needs)
Code:
function stripRealmName (name)
local newname = string.match(name, "[^ ]*")
return newname
end
Matching that way will match any name, even without spaces, so we can avoid the "check" first. It's not strictly necessary though, but if you do it your way with the space-check first, you'll probably want to use "(.*) " or "(.*)%s" instead of just ".* " or ".*%s". The () around the .* are a capture group, which is used to make sure you don't also grab the trailing space itself even though you are checking for it, which is what happens in your example.
Another thing to note here is there are slight differences in where these things will match should the string contain multiple spaces. "(.*) " will match until the last space in the string, for example, but "[^ ]*" will match until the first.
Another thing to think about, though, is other situations where a unit's name might have spaces. Obviously NPCs and such won't be party members, but player's pets and vehicles might have spaces in them. So if we did have to do the stripping manually, it might be necessary to check for the full " (*)" with a pattern like " %(%*%)" or even with a UnitIsPlayer call. However, directly using UnitName means we don't have to bother with that either.