开发者

need to strip out unwanted text

I need to strip out all text before and including "(" and all text after and including ")" in this variable.

var this_href = $(this).attr('href');

The above code produces this...

javascript:change_option('SELECT___100E___7',21)开发者_StackOverflow;

However it can produce any text of any length within the parenthesis.

A Regex solution is OK.

So in this case I want to end up with this.

'SELECT___100E___7',21


Rather than stripping out what you don't want you can match want you want to keep:

/\((.*?)\)/

Explanation:

\(    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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜