Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Matching a unknown range of lines

Matching a unknown range of lines

Scheduled Pinned Locked Moved Regular Expressions
regexhelptutorialquestion
2 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15505153
    wrote on last edited by
    #1

    I can't quite figure our how to define the expression to match the following. I have a number of places in files where lines contain "START FAILSAFE" and "STOP FAILSAFE" with a varying number of lines between. I would like to match these lines and replace them with an empty line. Anyone have a suggestion? Thanks!

    Public Function MyFunction1() As Integer
    '*** START FAILSAFE *********
    If Not fsDISABLED Then On Error GoTo FailSafe_Error
    '*** STOP FAILSAFE **********
    A number of lines of code to remain
    A number of lines of code to remain
    A number of lines of code to remain
    Exit function

    FailSafe_Error:
    '*** START FAILSAFE **********
    A number of lines of code to be deleted
    A number of lines of code to be deleted
    A number of lines of code to be deleted
    '*** STOP FAILSAFE **********
    End Function

    Public Function MyFunction2() As Integer
    '*** START FAILSAFE *********
    If Not fsDISABLED Then On Error GoTo FailSafe_Error
    '*** STOP FAILSAFE **********
    A number of lines of code to remain
    A number of lines of code to remain
    A number of lines of code to remain
    A number of lines of code to remain
    Exit function
    FailSafe_Error:
    '*** START FAILSAFE **********
    A number of lines of code to be deleted
    A number of lines of code to be deleted
    A number of lines of code to be deleted
    A number of lines of code to be deleted
    '*** STOP FAILSAFE **********
    End Function

    P 1 Reply Last reply
    0
    • M Member_15505153

      I can't quite figure our how to define the expression to match the following. I have a number of places in files where lines contain "START FAILSAFE" and "STOP FAILSAFE" with a varying number of lines between. I would like to match these lines and replace them with an empty line. Anyone have a suggestion? Thanks!

      Public Function MyFunction1() As Integer
      '*** START FAILSAFE *********
      If Not fsDISABLED Then On Error GoTo FailSafe_Error
      '*** STOP FAILSAFE **********
      A number of lines of code to remain
      A number of lines of code to remain
      A number of lines of code to remain
      Exit function

      FailSafe_Error:
      '*** START FAILSAFE **********
      A number of lines of code to be deleted
      A number of lines of code to be deleted
      A number of lines of code to be deleted
      '*** STOP FAILSAFE **********
      End Function

      Public Function MyFunction2() As Integer
      '*** START FAILSAFE *********
      If Not fsDISABLED Then On Error GoTo FailSafe_Error
      '*** STOP FAILSAFE **********
      A number of lines of code to remain
      A number of lines of code to remain
      A number of lines of code to remain
      A number of lines of code to remain
      Exit function
      FailSafe_Error:
      '*** START FAILSAFE **********
      A number of lines of code to be deleted
      A number of lines of code to be deleted
      A number of lines of code to be deleted
      A number of lines of code to be deleted
      '*** STOP FAILSAFE **********
      End Function

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Assuming that the regex engine you are using supports the dotall operator, you can use the following:

      '\*\*\* START FAILSAFE \*\*\*\*\*\*\*\*\*(.*?)'\*\*\* STOP FAILSAFE \*\*\*\*\*\*\*\*\*\*

      Alternatively, you could use

      '\*\*\* START FAILSAFE \*\*\*\*\*\*\*\*\*[\w\W]*?'\*\*\* STOP FAILSAFE \*\*\*\*\*\*\*\*\*\*

      Advanced TypeScript Programming Projects

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups