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. Visual Basic
  4. Regex Problem

Regex Problem

Scheduled Pinned Locked Moved Visual Basic
regexhelpquestiondatabasecollaboration
6 Posts 3 Posters 49 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi there everyone, I'm trying to do what is basically a String.Replace but not quite. I have a string e.g. "{Team}/{Team} Index" and a hashtable of replacement string values, e.g. "Wigan Athletic", "Manchester United". I need to loop through the hashtable and replace the first occurrence of the substring "{Team}" with "Wigan Athletic", and then on the next iteration replace the substring "{Team}" with "Manchester United". The problem I've got is (obviously) String.Replace replaces all occurrences of "{Team}" the first time through, and using regex every expression I write seems to select both occurrences. Is there a way to stop the regex matching after hitting the first match? Or otherwise some method of doing this that I'm just missing? Any help much appreciated :) Thanks, James

    A P 2 Replies Last reply
    0
    • L Lost User

      Hi there everyone, I'm trying to do what is basically a String.Replace but not quite. I have a string e.g. "{Team}/{Team} Index" and a hashtable of replacement string values, e.g. "Wigan Athletic", "Manchester United". I need to loop through the hashtable and replace the first occurrence of the substring "{Team}" with "Wigan Athletic", and then on the next iteration replace the substring "{Team}" with "Manchester United". The problem I've got is (obviously) String.Replace replaces all occurrences of "{Team}" the first time through, and using regex every expression I write seems to select both occurrences. Is there a way to stop the regex matching after hitting the first match? Or otherwise some method of doing this that I'm just missing? Any help much appreciated :) Thanks, James

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      There are several versions of the Regex Replace method available. One allows you to specify the maximum number of replacements to make.

      L 1 Reply Last reply
      0
      • A andyharman

        There are several versions of the Regex Replace method available. One allows you to specify the maximum number of replacements to make.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thank you very much, I noticed that about 5 seconds before you replied. Thanks, Jim

        1 Reply Last reply
        0
        • L Lost User

          Hi there everyone, I'm trying to do what is basically a String.Replace but not quite. I have a string e.g. "{Team}/{Team} Index" and a hashtable of replacement string values, e.g. "Wigan Athletic", "Manchester United". I need to loop through the hashtable and replace the first occurrence of the substring "{Team}" with "Wigan Athletic", and then on the next iteration replace the substring "{Team}" with "Manchester United". The problem I've got is (obviously) String.Replace replaces all occurrences of "{Team}" the first time through, and using regex every expression I write seems to select both occurrences. Is there a way to stop the regex matching after hitting the first match? Or otherwise some method of doing this that I'm just missing? Any help much appreciated :) Thanks, James

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Is this an old question or a new one? Or has your account been hacked?

          L 1 Reply Last reply
          0
          • P PIEBALDconsult

            Is this an old question or a new one? Or has your account been hacked?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Looks to me like something went wrong at CodeProject.

            P 1 Reply Last reply
            0
            • L Lost User

              Looks to me like something went wrong at CodeProject.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Dunno. It showed up in moderation yesterday.

              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