2016-12-14 8 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" 
関連する問題