It sure makes sense, but - honestly - I still don't get it completely. It's like looking around two corners and with mirrors facing each other, WTF?! I'm a practical thinking person, too much theory for my small and aging head... Nevertheless, I never give up and this offers levers to adjust the expressions to make them do what I need.Technically, the .*? locally inverted the (standard greedy behavior) overall inversion by (?U) at the start, if it makes sense.
Turns out, today I noticed another complexity in the CNBC data: For <curmktstatus> they actually have 3 different variants: REG_MKT, PRE_MKT and POST_MKT! If one of the latter two is "set" we need to grab the <extendedMktQuote> price-data. I actually googled a regex solution called "negative lookahead" --> now using (?!REG_MKT) to find both alternatives. However, as it turned out due to the positioning of the <extendedMktQuote> block BETWEEN the <last>, <change> and <change_per> tags, I needed to modifiy the greedy/lazy switch only for <change> and <change_per> ... By the way, initially I started with (REG_MKT|PRE_MKT) as alternative words expression, but due to the following .* this expression always failed because it was used as "match" and maybe because it is already part of "branch reset group"? WTF^2.
Long-story-short - the below code seems to cover all variants that I'm aware of, as of today. We need 3 (actually 2) different expressions for the 3 relevant tags - this will always give prio1 to <extendedMktQuote> if REG_MKT is not active and it delivers the correct corresponding regular price data [f REG_MKT is running!
Code:
; Price e.g. [mIndex1_Price]RegExp=(?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<last>(.*)<\/last>.*?|.*?<last>(.*)<\/last>); Price change e.g. [mIndex1_UpDown]RegExp=(?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<change>(.*)<\/change>.*?|.*<change>(.*)<\/change>); Price change% e.g. [mIndex1_ChangePer]RegExp=(?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<change_pct>(.*)<\/change_pct>.*?|.*<change_pct>(.*)<\/change_pct>)
In the end, I really invested several hours of testing with sweat, tears & black coffee. Thanks to regex101.com (I like it better, just because it directly displays the relevant match) I permutated the above 3 expressions on the 3 xml variants for several stocks and a few others that I saved... Hard, hard work. Yeah, I wanted to use ChatGPT but since I always thought "I'm so close, I can do it" -> never asked "the machine": all human-made. Learned a lot, but still don't understand more than 5% of regex basics. But who cares if "it works" - still I'm very open for any improvements and corrections of potential mistakes or redundancies in my hacky mess of regex code.
I will also confirm if this turns out to be robust in the coming days. Need to get confidence, hoping not to find another CNCB-tripwire... Hasta-la-vista, over-and-out. Regex is cool, kindof - WTF^3. Amen.



Statistics: Posted by emp00 — Yesterday, 8:47 pm