\D matches a character that is not a numerical digit and the non digit characters will be replaced by an empty string resulting in only the digits in a string.So if we negate that, we will get all non-numeric characters.The g at the end of the regular expression literal is for "global" meaning that it replaces all matches. So all the 3 shown above will work