所以我想申请清理我所拥有的字符串的规则是:
搜索最后一个字符,其中包含A-Z / i之间的字母,并删除其后的所有字符。像这样:
"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)
答案 0 :(得分:0)
我发现它,使用:[^ A-Z] + $
console.log("WASHER,".replace(/[^A-Z]+$/,""))
console.log("VALVE,NEEDLE,".replace(/[^A-Z]+$/,""))
console.log("HOSE,HYDRAULIC. 3466".replace(/[^A-Z]+$/,""))
console.log("WASHER . ".replace(/[^A-Z]+$/,""))