Forgive me, but regex is simply beyond me. I'm trying to use javascript to remove all non-numeric characters from a user input except the letter "m" in the first position. I had this code which removes all non-numerics:
userInput.replace(/\D/g, '')
I'd like to modify this to not replace an "m" or "M" at the first position in the string, so
m490-333bA
would become
m490333
Any thoughts?
您可以使用类似以下的表达式:
str.replace(/(?!^m)\D/ig, "");
您可以使用负数前瞻 :
userInput.replace(/(?!^M)\D/gi, '')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.