Let's say I have these two strings: "5/15/1983" and "1983.05.15". Assume that all characters in the string will be numeric, except a "separator" character that can appear anywhere in the string. There will be only one separator character; all instances of any given non-numeric character in the string will be identical.
How can I use regex to extract this character? Is there a more efficient way than the one below?
"05-15-1983".replace(/\d/g, "")[0];
Thanks!
"05-15-1983".match(/\D/)
Technically, this returns an array containing one string, but it will implicitly convert to the string most places you need this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With