开发者

Regular Exp. in Eclipse, Find and Replace: Match everything between curly braces

I would like to match everything between and including curly braces in eclipse find and replace (it can be assumed that there are no inner curly braces but any other character including all types of whitespace.

int SomeMethodName() {
   // TODO Auto-generated method stub
   re开发者_JS百科turn asdfasdf.rearoiula12123893;
}

Right now I am trying this and it only matches curly braces with nothing in them \{[.\s]*\}


The . inside a character class means a . literal, not a wildcard. You need something more like:

\{.*?\}

Depending on how Eclipse treats new line characters you might need to change it to:

\{(.|\r\n?|\n)*?\}


This should work. Tested using Regex Powertoy here.

\{[\s\W\w]*\}

EDIT:

\{[\s\w\. /=(":);]*\} should stop at the nearest closing brace. The piece after the space has all the miscellaneous non-word characters, so you might have to add to that depending on the nature of what you're parsing (e.x. a weird String).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜