开发者

Javascript regular expression to remove characters from the end of a string

开发者 https://www.devze.com 2023-02-04 23:26 出处:网络
I have a couple strings like: net_weight_(lbs) 开发者_开发百科net_height_(inches) I need a regular expression that will remove the _(x) from the end of the string.So in my two examples, I would be

I have a couple strings like:

net_weight_(lbs)
开发者_开发百科net_height_(inches)

I need a regular expression that will remove the _(x) from the end of the string. So in my two examples, I would be left with:

net_weight
net_height

Any help would be greatly appreciated


If you'd prefer not to use regular expressions you can use lastIndexOf('_') and the get the substring up to that index.

s = s.substr(0, s.lastIndexOf('_'));

http://jsfiddle.net/Z7qrW/

0

精彩评论

暂无评论...
验证码 换一张
取 消