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. String Replacement

String Replacement

Scheduled Pinned Locked Moved Regular Expressions
csharpvisual-studiobeta-testingtutorialquestion
6 Posts 2 Posters 23 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
    Michael Eckstein
    wrote on last edited by
    #1

    Hi, I'd lke to subsitute the string Alfa("Beta") to Alfa(Gamma("Beta")) using regular expressions in Visual Studio using regexp. The first part is simple, the search string will be Alfa\("(.*)"\) But how to specify the replacement string? I used Alfa\(Gamma\("(.*)"\)\) , but the result was Alfa(Gamma("(.*)")) and not the requested Alfa(Gamma("Beta")) Thank you for your advice in advance

    L 1 Reply Last reply
    0
    • M Michael Eckstein

      Hi, I'd lke to subsitute the string Alfa("Beta") to Alfa(Gamma("Beta")) using regular expressions in Visual Studio using regexp. The first part is simple, the search string will be Alfa\("(.*)"\) But how to specify the replacement string? I used Alfa\(Gamma\("(.*)"\)\) , but the result was Alfa(Gamma("(.*)")) and not the requested Alfa(Gamma("Beta")) Thank you for your advice in advance

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

      You need to use the capture operation to use the value from the regex as a replacement parameter. See Use regular expressions - Visual Studio | Microsoft Docs[^].

      M 2 Replies Last reply
      0
      • L Lost User

        You need to use the capture operation to use the value from the regex as a replacement parameter. See Use regular expressions - Visual Studio | Microsoft Docs[^].

        M Offline
        M Offline
        Michael Eckstein
        wrote on last edited by
        #3

        Thank you! :)

        1 Reply Last reply
        0
        • L Lost User

          You need to use the capture operation to use the value from the regex as a replacement parameter. See Use regular expressions - Visual Studio | Microsoft Docs[^].

          M Offline
          M Offline
          Michael Eckstein
          wrote on last edited by
          #4

          Hi Richard, I used your advice and it worked perfectly. The search string was alfa\("(.*)"\) and the regexp substitute string was alfa(gamma("$1")) Thus I obtained the wished result string alfa(gamma("beta")) But one more question: I encountered an input string alfa("beta","delta") and the wished result string should be alfa(gamma("beta"),"delta"), but I obtained alfa(gamma("beta","delta")) How to change regexp to achieve this? Thank you, best regards, Michael

          M 1 Reply Last reply
          0
          • M Michael Eckstein

            Hi Richard, I used your advice and it worked perfectly. The search string was alfa\("(.*)"\) and the regexp substitute string was alfa(gamma("$1")) Thus I obtained the wished result string alfa(gamma("beta")) But one more question: I encountered an input string alfa("beta","delta") and the wished result string should be alfa(gamma("beta"),"delta"), but I obtained alfa(gamma("beta","delta")) How to change regexp to achieve this? Thank you, best regards, Michael

            M Offline
            M Offline
            Michael Eckstein
            wrote on last edited by
            #5

            Maybe so? alfa\("([^"]*)"(.*) replace with alfa(gamma("$1")$2

            L 1 Reply Last reply
            0
            • M Michael Eckstein

              Maybe so? alfa\("([^"]*)"(.*) replace with alfa(gamma("$1")$2

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

              I am not a regex expert I am afraid. But You can go to RegExr: Learn, Build, & Test RegEx[^], and try different sets to see what may work.

              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