开发者

How to use regular expression extract the number inside the ()?

Here is example text...

ss(12a)eee
ss(121112322开发者_如何转开发)eeede223

I would like to extract "121112322" ... ... I can extract the "(121112322)", using this

\(\d*\)

But I would like to exclude the "()", and the text must inside the (), how can I do so? Thank you.


Regular expressions provide ways to capture buffers. Check this document on how to capture buffers with Perl, which is pretty universal.

Basically, you need to wrap up the piece of regex you want to capture in unescaped parenthesis:

(\(\d*\))

By convention, in buffer 0 you'll have the whole string, and in buffer 1 you'll have the first captured buffer.


This should do it.

\((.*)\)

The first group will be the value inside the brakets -- an example of usage in javascript

var test = 'sfsfsdfsdf(12a)sdfsdfsdf';
var r = test.match(/\((.*)\)/)
console.log(r[1]) // <--- bracket inners

and to see it in action

http://jsfiddle.net/tAm2d/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜