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 separate regions

Matching separate regions

Scheduled Pinned Locked Moved Regular Expressions
regexhelptutorial
4 Posts 2 Posters 9 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_14504433
    wrote on last edited by
    #1

    Hi, I'm using Notepad++ to do some Regex replacements and have come up against a problem I can't solve. I'm looking to match a region between two fixed strings inclusive (called and for the sake of example). The problem I have is these strings appear multiple times throughout, but I want to match EACH instance, rather than one match from the very first to the last . They may or may not be over many lines. For example: ...text body... ...other text... ...text body... ...other text... ...text body... I need my Regex to make 3 separate matches, rather than 1 big match which includes all the ..other text... which I need to be left intact. The above needs to work irrespective of whether the and are on the same line or many lines apart. Thanks in advance.

    OriginalGriffO 1 Reply Last reply
    0
    • M Member_14504433

      Hi, I'm using Notepad++ to do some Regex replacements and have come up against a problem I can't solve. I'm looking to match a region between two fixed strings inclusive (called and for the sake of example). The problem I have is these strings appear multiple times throughout, but I want to match EACH instance, rather than one match from the very first to the last . They may or may not be over many lines. For example: ...text body... ...other text... ...text body... ...other text... ...text body... I need my Regex to make 3 separate matches, rather than 1 big match which includes all the ..other text... which I need to be left intact. The above needs to work irrespective of whether the and are on the same line or many lines apart. Thanks in advance.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Try:

      public static Regex regex = new Regex(
      "\\.*?\\",
      RegexOptions.Singleline
      | RegexOptions.CultureInvariant
      | RegexOptions.Compiled
      );
      ...
      MatchCollection ms = regex.Matches(InputText);

      Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      M 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Try:

        public static Regex regex = new Regex(
        "\\.*?\\",
        RegexOptions.Singleline
        | RegexOptions.CultureInvariant
        | RegexOptions.Compiled
        );
        ...
        MatchCollection ms = regex.Matches(InputText);

        Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        M Offline
        M Offline
        Member_14504433
        wrote on last edited by
        #3

        Thanks, that's led me to the correct solution for all eventualities :thumbsup:

        OriginalGriffO 1 Reply Last reply
        0
        • M Member_14504433

          Thanks, that's led me to the correct solution for all eventualities :thumbsup:

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          You're welcome!

          Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          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