2014-02-22 10 views

回答

3

試試這個:

var str = 'ajay kumar (68766)'; 
str = str.slice(str.indexOf('(')+1, str.indexOf(')')); 
+0

thanq ... 如何存儲STR(值)在下一個文本框字段? –

+0

如果你有一個如下的文本框:''input type =「text」id =「box」>'你可以將該值放在該文本框中:'document.getElementById('box')。value = str;' –

+0

hmm是的它的工作... –

0

如何使用正則表達式?

var str = 'ajay kumar (68766)'; 
var output = str.replace(/^[\s\S]*?\((\d+)\)[\s\S]*?$/, '$1'); 
+0

不適用於我:/ –

+0

它似乎刪除括號,但前括號之前的文字是完整的。 –

+0

@DanielLisik對不起,我犯了一個錯誤。我已經更正了現在的代碼。 – Toothbrush