2016-12-14 16 views

回答

1

您可以使用各種選項來獲取所需的字符串。

//With regular expression with split() and fetch the first element of array 
 
console.log('sringggg(125)'.split(/\(\d+\)/)[0]); 
 

 
//Using string with split() and fetch the first element of array 
 
console.log('sringggg(125)'.split('(')[0]); 
 

 
//Using substr and indexOf 
 
var str = 'sringggg(125)' 
 
console.log(str.substr(0, str.indexOf('(')));

參考

+1

謝謝you..it作品 –

0

如果字符串總是在相同的模式和 '(' 是一個隔膜用分裂。

var string = 'string(1)' 
var result = string .split('(')[0]; 
0

嘗試使用正則表達式

var tesst = "string(1)" 
var test = tesst.match(/^[^\(]+/); 
// test = "string" 
相關問題