Build, test, and debug regular expressions
This regex matches any non-digit character except a leading minus sign at the very start of the string. The negative lookahead (?!^\-) preserves an initial hyphen so negative numbers survive. Used with String.replace() and the global flag, it strips everything except digits and the sign, e.g. turning "abc-12" into "12" while keeping "-42" as "-42". Ideal for sanitizing numeric user input.