[英]Javascript regular expression to extract characters from mid string with optional end character
[英]Javascript regular expression to remove characters from the end of a string
我有幾個像這樣的字符串:
net_weight_(lbs)
net_height_(inches)
我需要一個正則表達式,該正則表達式將從字符串的末尾刪除_(x)
。 因此,在我的兩個示例中,我將得到:
net_weight
net_height
任何幫助將不勝感激
如果您不想使用正則表達式,則可以使用lastIndexOf('_')
並獲取直到該索引的子字符串。
s = s.substr(0, s.lastIndexOf('_'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.