正则表达式 - 如何在块中查找特定文本?

Tim*_*Tim 1 regex

我是正则表达式的新手,并希望使用一个来搜索我们的源代码控件,以查找遵循特定枚举值的代码块中的文本.即:

/(\/{2}\@debug)(.|\s)*?(\/{2}\@end-debug).*/
var junk = dontWantThis if (junk) {dont want this} if ( **myEnumValue** ) **{ var yes = iWantToFindThis if (true) { var yes2 = iWantThisToo } }**
var junk2 = dontWantThis if (junk) {dont want this}  
var stuff = dontWantThis if (junk) {dont want this} if ( enumValue ) { wantToFindThis }
var stuff = iDontWantThis if (junk) {iDontWantThisEither}
Run Code Online (Sandbox Code Playgroud)

我知道我可以(\{(/?[^\>]+)\})用来查找块,但我只想要第一个包含我想要的枚举值的代码块.我也注意到use使用(\{(/?[^\>]+)\})了第一个{和最后一个},它不会对后续组合{}.

谢谢!
蒂姆

avi*_*ldg 6

Regexps根本无法处理这种东西.为此,您需要一个解析器和扫描仪.