我需要删除此变量中“(”之前和包括“(”的所有文本以及“)”之后和包括“)”的所有文本。
var this_href = $(this).attr('href');
上面的代码产生了这个...
javascript:change_option('SELECT___100E___7',21);
但是它可以在括号内生成任何长度的任何文本。
Regex 解决方案就可以了。
所以在这种情况下,我想以此结束。
'SELECT___100E___7',21
最佳答案
而不是剥离你不想要的东西,你可以匹配你想要保留的东西:
/\((.*?)\)/
解释:
\( Match an opening parenthesis. ( Start capturing group. .*? Match anything (non-greedy so that it finds the shortest match). ) End capturing group. \) Match a closing parenthesis.
Use like this:
var result = s.match(/\((.*?)\)/)[1];
关于javascript - 需要去掉不需要的文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4057639/