Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
RegEx and complex pattern
Message
 
 
À
Tous
Information générale
Forum:
C#
Catégorie:
Code, syntaxe and commandes
Titre:
RegEx and complex pattern
Divers
Thread ID:
01665645
Message ID:
01665645
Vues:
73
Hi everybody,

We have the following code:
public static Regex XMLRegex = new Regex(@"<(?<field>[^/>]+)>(?<data>.*)</\k<field>>", RegexOptions.Compiled | RegexOptions.Singleline);
and then
MatchCollection matches = XMLRegex.Matches(tcSQML);
         foreach (Match m in matches)
         {
            if (!tDictionary.ContainsKey(m.Groups["field"].ToString()))
               tDictionary.Add(m.Groups["field"].ToString(), m.Groups["data"].ToString().Trim());
         }
Unfortunately, we found a case where this pattern doesn't work, e.g.
<func>appendrecs</func><tcoperator>ADMIN</tcoperator>
<tcrecorddata>CHARGEDATE0001902/28/2019 00:00:00SALE_TEXT 00429<func>PaymentPlanCharge</func><orig_amount>125</orig_amount>SALESPOINT00006DANAIITRANSTYPE 000010</tcrecorddata>
<tcsalespoint>DANAII032001</tcsalespoint><tctablename>WW_SALES</tctablename>
In other words, the tcRecordData contains SALE_TEXT which in turn contains some XML like text. We need to parse the above string properly into a few parameters, in particular, the FUNC parameter is supposed to be "AppendRecs" but with the code above it becomes a complex text ending with the last /func

(I removed some of the non relevant info from the input string).

Is there a way to solve this problem?

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform