开发者

Matching Parantheses Using a regular expression

I am trying to write a regular expression to match any string that satisfies the following criteria.

The string begins and ends with a matching pair of parentheses '(' ')'

There may be any number of parentheses within it.

For example my regex shud match :

( ( p(x)+q(x) ) . (p(x) * q(x)开发者_如何学JAVA ) )

but not match

( p(x)+q(x) ) . ( p(x) * q(x) )

How do i write such a regex


Please do a better search next time: http://www.google.com/search?q=site%3Astackoverflow.com+regex+match+parentheses&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

Here's your answer: Regular Expression to match outer brackets


Doing any sort of parsing like this using regular expressions is difficult and almost always a bad idea. See this answer to this question. Oh, the horror!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜