I'm a little torn. There is a fun but poorly communicated question asked. It has been closed and downvoted. It also looks like someone's homework. I've got an elegant pure regex solution, but I am hesitant to vote to reopen because the mcve is both large and incomplete and hard to understand without studying the question. Very unlikely to help future readers. How much patience/lenience would you grant the new asker?
stackoverflow.com/q/78739989/2943403 php