Reputation: 4886
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
Upvotes: 2
Views: 68
Reputation: 70732
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.
Upvotes: 3