Search code examples
regexemeditor

Regex to match Function...End Function for folding purposes?


I use and I'm trying to modify the "Outline" setting so that I can collapse functions in VBS files and also so they'll show up in the outline window. Here is the dialog:

enter image description here

Obviously I tried the most basic thing I could think of since I don't do Regex but it did not work.

How would I match everything between Function and End Function?

Here is an example of the XML config which allows me to collapse any elements:

enter image description here


Solution

  • The straightforward solution is a non greedy any match:

    /Function.*?End Function/
    

    Depending on your tool (I'm not familiar with emeditor), "." may not match newlines! In that case use [\s\S] instead of the .. Don't forget the ? behind the *:

    /Function[\s\S]*?End Function/