s/<script>//gi

We get a big file like

SE<<s<SCRIpT>crIPT>S<Sc<SCRIPT>rIpt>Cr<S<SCriPt<sCRipt>>C<ScRIpt>RiPT>Ipt<scrI<<
SCrIpt>scriPt<ScRi<sCriPt>pt><SCripT>>p<script>T>>CCON{sani<sCRIpT><<ScrIP<s<scR
I<SCripT>pT>cri<ScRIpT>pt>T><ScRip<<SCrIpT><sCriPt>Sc<ScRiPT><Script>ri<ScRIpT>P
t><s<sCrIPT>CrIpT>T>sCRIPt><Sc<ScrIpt>r<sCriPt>Ipt<sCRipt>><Scr<s<ScRiPt>CrIpt<S
<scrIPT<sCRiPt>><SCrIPt>c<sC<<SCRipt>ScriPt>RIPt>ri<ScRIpT>pt<SCRIpT>>><ScRipT<s
CriPT><Sc<scR<scRIpt>IPT><scRIpT><ScRIpt><SCript>RI<ScrI<SCrIP<ScrIpT>T>Pt>Pt>>I
<ScRIPt>PT<ScRi<sCriPt><SCrIpT>pt>><s<scRipt>CriPt>tiz<S<sCRip<S<sCRIpT><ScrIp<s
CrIPt>T>CrI<sCRiPT>Pt><scRipt>t><sc<<scRipt>sC<s<ScrIpT>cRIpT><sCRipt>r<ScRIpT>I
<Scr<ScRIPt>i<SCRIpt><ScR<s<SCRipt>CrIpt>iPT>P<scRIpT>t>pT<sC<SCripT>RiPT>><scri
pT>RipT<sCRI<scriPt>pT>><<scRIPt<SCRIPT>>ScR<scrIPT>iP<s<ScRiPT><Sc<sC<ScriPT><s
...

and after replacing however many millions of <script> tags only the flag should remain.

Did this one under severe time pressure, which of course means you try the worst solutions first. Tried a regex which replaced two layers of nested strings at the same time. It starts out great, but quickly falls into quicksand because it seems there are around 16 or so (?) huge “towers” of nested strings (like a degenerate tree where each node only has one child).

So from there I moved on to the second worst solution, where I took the resulting string with these “towers” and sliced them off at the base simply by string-scanning forward on <> characters, not caring about anything else, reasoning that surely they could not be part of the flag.

It worked and got the flag, but it was a shitty ad-hoc solution.

The right solution (I realize now) would have been to just write simple, straightforward loop that keeps a stack of strings at each level. I had discarded this idea from the get-go, because I misread the size of the file (~64MB) as ~640MB, assuming that a Python loop that iterates per character was totally out of the question.