can anyone please tell me how to remove the last numbers before the space using Regular Expression in javascript
ABCD 154 => ABCD
ACR 15 => ACR
SA 12S 8945 => SA 12S
Use the end of string $
anchor to replace the preceding space and numbers that follow at the end of the string.
str = str.replace(/ [0-9]+$/, '');
If you want to retain the space character, just remove it from the regular expression.
尝试
'SA 12S 8945'.replace(/\s\d+$/, '')
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.