English 中文(简体)
2008年VS2008年REGEX搜索中的高流量
原标题:Stack overflow in REGEX search in VS2008

I am trying to find in a huge COBOL file if all the "IF" have a corresponding "END-IF". Using Visual Studio 2008 as I know it has a search tool with a regex feature. (Though, I know after reading Jeff Atwood s article about it, that the regex in Visual Studio are not quite the same than the real deal.)

Anyway, I came up with this expression:

<(IF)#(.*
*)#END-IF

That seems to overflow the stack, quite inconveniently (see picture below). So I was wondering, if it was at all possible to do this kind of search in VS ? And if it is, what would the regex look like ?

-->I want to know if all "IF" have a closing "END-IF"

感谢。

“stack

最佳回答

What you have here is a case of trying to perform recursive parsing with a regular expression, and generally that s going to get you into trouble. As I read it (granted, I am not familiar with the flavor used by Visual Studio here), your regex tries to match as many lines as it can until it finds an END-IF -- including matching another END-IF. In other words, when presented with

IF condition-1
    statement-1
END-IF
IF condition-2
    statement-2
END-IF

one match is found, not two.

Also, think about how you want to deal with this case:

IF condition-1
    IF condition-2
        statement-1
    END-IF
END-IF

除非你试图书写自己的语言翻译或COBOL灯塔工具,否则,我认为你可以听说,编辑们将找到你相应的数字,或者在一段末尾悬挂一个未公开的综合框架。

问题回答

暂无回答




相关问题
building .net applications without Visual Studio

I m interested to hear about people working with building .net applications using MSBuild, NAnt or similar tools. What are you using, why are you using it instead of the VS IDE? I like to use ...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Visual Studio 2010 Beta 2: Can I print in color?

I have to turn in a hard copy of some code with an assignment. Is there any way in Visual Studio 2010 to print C# source code with syntax highlighting? PS: The assignment is solving a math problem, ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

热门标签