3 ms·
In 30 years of developing software I don’t think I ever used multi-line regexp even once.
by Scubabear68 3y ago
In 30 years of developing software I don’t think I ever used multi-line regexp even once.
- thrdbndndn 3y agoDefinitely not common, but if you are parsing a text file you're going to use it a lot (say, you're writing a JS parser).
- marcosdumay 3y agoYou really shouldn't use a lot of regexes for parsing code. They go only on the tokenizer, if they go somewhere at all.
- thrdbndndn 3y agoAgreed, it's more about quick and dirty ad hoc capture than full-fledged parser though (like when you want to extract certain object when scraping).
- Terretta 3y ago> In 30 years of developing software I don’t think I ever used multi-line regexp even once. As long as sharing anecdata, in 30 years, it's almost the only way I use it. It's incredible for slicing and dicing repetitious text into structure. You generally want some sort of Practical Extraction and Reporting Language, the core of which is something like a regular expression, generally able to handle the, well, irregularity. Most recent example (I did this last week) was extracting Apple's app store purchases from an OCR of the purchase history available through Apple's Music app's Account page that lets you see all purchases across all digital offerings, but only as a long scrolling dialog box (reading that dialog's contents through accessibility hooks only retrieves the first few pages, unfortunately). Each purchase contains one or more items and each item has one or more vertical lines, and if logos contain text they add arbitrary lines per logo. A good match and sub match multi-line regex folds that mess back into a CSV. In this case, the regex for this was less than an 80 char line of code and worked in the find replace of Sublime Text which has multiline matching, subgroups, and back references. Another way to do this is something like a state match/case machine, but why write a program when you can just write a regular expression?