String Replacement
-
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
-
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
-
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[^].
Thank you! :)
-
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[^].
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
-
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
Maybe so? alfa\("([^"]*)"(.*) replace with alfa(gamma("$1")$2
-
Maybe so? alfa\("([^"]*)"(.*) replace with alfa(gamma("$1")$2