I need regexp to remove all not digits and not dash (‘-‘). new RegExp('[^0-9-]') seems works but new RegExp('[\\D-]') remove dash also. Why is this different?
I need regexp to remove all not digits and not dash (‘-‘). new RegExp(‘[^0-9-]’)
Share
[^0-9-]is “anything that is NOT a digit, or is NOT a dash[\D-]is “anythign that is NOT a digit, or IS a dashthe
^inverts the entire[]character class, so on your\Dversion, there’s no inversion, so a-is a legitimate match.