Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Multi Line Select

Last post 07-01-2009, 6:06 PM by ddrudik. 3 replies.
Sort Posts: Previous Next
  •  06-30-2009, 2:43 PM 54452

    Multi Line Select

    I am trying to perform a select on multiple lines of code that are being generated wrong.

     Here is an example:

    Public Overrides Sub Test

       applyAction(a)

       applyAction(b)

       applyAction(c)

    End Sub

     I am wanting to select all text between Test and End Sub. I know how to select from a single line but cannot figure out how to select the three lines. This is a sub that appears in multiple classes and can have more than just 3 lines to replace.

  •  06-30-2009, 2:57 PM 54453 in reply to 54452

    Re: Multi Line Select

    VB.NET Code Example:
    Imports System.Text.RegularExpressions
    Module Module1
      Sub Main()
        Dim sourcestring as String = "replace with your source string"
        Dim re As Regex = New Regex("Sub Test(.*?)End Sub",RegexOptions.Singleline)
        Dim mc as MatchCollection = re.Matches(sourcestring)
        Dim mIdx as Integer = 0
        For each m as Match in mc
          For groupIdx As Integer = 0 To m.Groups.Count - 1
            Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
          Next
          mIdx=mIdx+1
        Next
      End Sub
    End Module


    Matches Found:
    [0][0] = Sub Test

       applyAction(a)

       applyAction(b)

       applyAction(c)

    End Sub
    [0][1] =

       applyAction(a)

       applyAction(b)

       applyAction(c)



  •  07-01-2009, 4:28 PM 54482 in reply to 54453

    Re: Multi Line Select

    Looks like this maybe more difficult then I thought. I have to apply this across several files and was just hoping I could use the find and replace feature using Regular Expressions inside of Visual Studio. Considering that the objects are still in early stages of Development I will be regening the objects fairly often.

     Hopefully our provider will have this bug worked out of the object generator soon.

  •  07-01-2009, 6:06 PM 54484 in reply to 54482

    Re: Multi Line Select

    In VS find/replace that would be:

    Sub Test(.|\n)@End Sub

    http://msdn.microsoft.com/en-us/library/2k3te2cs.aspx


View as RSS news feed in XML