I have the below situation
Case 1:
Input : X(P)~AK,X(MV)~AK
Replace with: AP
Output: X(P)~AP,X(MV)~AP
Case 2:
Input: X(PH)~B$,X(PL)~B$,X(MV)~AP
Replace with: USD$
Output: X(PH)~USD$,X(PL)~USD$,X(MV)~USD$
As can be make out that, always the ~<string> will be replaced.
Is it possible to achieve the same through regular expression?
Note:~ Nothing will be known at compile time except the structure. A typical structure
goes like
X(<Variable Name>)~<Variable Name>
I am using C#3.0
This simple regex will do it:
~(\w*[A-Z$])You can test it here:
http://regexhero.net/tester/
Select the tab Replace at RegexHero.
Enter
~(\w*[A-Z$])as the Regular Expression.Enter
~APas the Replacement string.Enter
X(P)~AK,X(MV)~AKas the Target String.You’ll get this as the output:
In C# idiom, you’d have something like this: