开发者

javascript regular expression matching help

I want to write a regex that matches the "()" one time in:

hello()
hello(asd, 2)
hello(asd,sad)开发者_StackOverflow中文版)

That is, the 1st and the 2nd one should match but not the 3rd one.

Also the () has to be at the end so:

hello(asd)q
hello(asd)-

wont match.

In other words I want the regex to help me know if the string is a valid function call so i can use eval() on it. Could someone help me out. Thanks.


this should do it

/(^|\s+)\w+\([^)]?\)$/

Or if the function call is the only code in the string

/^\s*\w+\([^)]?\)$/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜