remove parenthese from function like string
-
I have a similar string with a C++ function __X __X(" (whatever1)") alpha __X("whatever2") beta and I should remove the __X function and the corresponding parentheses, so the result should be "(whatever1)" alpha "whatever2" beta The argument to the __X function is a string embedded in "" and sometimes additionally embedded in () I'd appreciate any help, thanks in advance :-)
-
I have a similar string with a C++ function __X __X(" (whatever1)") alpha __X("whatever2") beta and I should remove the __X function and the corresponding parentheses, so the result should be "(whatever1)" alpha "whatever2" beta The argument to the __X function is a string embedded in "" and sometimes additionally embedded in () I'd appreciate any help, thanks in advance :-)
-
Does this simple Regex.Replace work for you?
string oldExp = @"__X(""(whatever1)"") alpha __X(""whatever2"") beta";
string newExp = Regex.Replace(Regex.Replace(oldExp, @"__X\(""", @""""), @"""\)", @"""");By whatever1 and whatever2 I meant that these strings are arbitrary, not just exactly whatever1(2). So it should work both for __X(" (Joe)") John __X("Silver") Doe with the result " (Joe)" John "Silver" Doe and __X(" (Jane)") Michael J. __X("Frank Sinatra") Fox with the result " (Jane)" Michael J. "Frank Sinatra" Fox I'd be happy even with replacing __X(" (Joe)") John was there for " (Joe)" John was there
-
By whatever1 and whatever2 I meant that these strings are arbitrary, not just exactly whatever1(2). So it should work both for __X(" (Joe)") John __X("Silver") Doe with the result " (Joe)" John "Silver" Doe and __X(" (Jane)") Michael J. __X("Frank Sinatra") Fox with the result " (Jane)" Michael J. "Frank Sinatra" Fox I'd be happy even with replacing __X(" (Joe)") John was there for " (Joe)" John was there
-
Regex that I gave you will work whatever the string inside parentheses is. It focuses on removing the __X(" and "). You can use this one for any __X
string newExp = Regex.Replace(Regex.Replace(oldExp, @"__\w+?\(""", @""""), @"""\)", @"""");
Is this possible to use in MS Visual Studio using 'Edit->Find and Replace->Replace in files' and checking 'Use regular expressions' and if so, then what should be in boxes 'Find what' and 'Replace with:' ? In fact, it is a revert replace from Find what: \("([^"]*)"(.*) Replace with: (__X("$1")$2
-
Is this possible to use in MS Visual Studio using 'Edit->Find and Replace->Replace in files' and checking 'Use regular expressions' and if so, then what should be in boxes 'Find what' and 'Replace with:' ? In fact, it is a revert replace from Find what: \("([^"]*)"(.*) Replace with: (__X("$1")$2
-
Yes, it can be done from Find and Replace in two steps. Find: __\w+?\(" Replace: " Find: "\) Replace: "
Hi moxol, thank you for your idea using two steps! I used this: Find: __X\("([^"]*)"(.*) Replace: "$1"q!@tr@$2 repeated n-times until no other replacement was made Then simply remove all q!@tr@) strings without regexp to remove the original closing parenthese, where q!@tr@ is any improbable string used as an identifier