[英]How do I use regex to remove any non alpha characters after last alpha character in string?
So the rule I would like to apply to clean the strings I have is:所以我想应用来清理我所拥有的字符串的规则是:
Search for last character in that has a letter between AZ/i and remove all characters after it.搜索在 AZ/i 之间有字母的最后一个字符,并删除其后的所有字符。 Like this:像这样:
"WASHER," -> "WASHER" (R is last alpha character)
"VALVE,NEEDLE," -> "VALVE,NEEDLE" (E is last alpha character)
"HOSE,HYDRAULIC. 3466" -> "HOSE,HYDRAULIC" (C is last alpha character)
"WASHER . " -> "WASHER" (R is last alpha character)
I found it, by using: [^AZ]+$我找到了,通过使用:[^AZ]+$
console.log("WASHER,".replace(/[^AZ]+$/,"")) console.log("VALVE,NEEDLE,".replace(/[^AZ]+$/,"")) console.log("HOSE,HYDRAULIC. 3466".replace(/[^AZ]+$/,"")) console.log("WASHER . ".replace(/[^AZ]+$/,""))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.