Reply To: Regex match multiline blocks between two identifiable lines

Product Compare Forums Multi-Edit Support Regex match multiline blocks between two identifiable lines Reply To: Regex match multiline blocks between two identifiable lines

#3293
ReidSweatman
Participant

Yes, the anchor at the start of the regex is necessary, and not a problem; it’s the ones following end anchors that don’t work.

I examined your original patterns. I’ve run into this in somewhat different form myself on a couple of occasions. I’ve no doubt this behavior is coded into the regex engine. The upcoming v9.1 release will have an entirely different and more powerful regex engine, so this will cease to be an issue soon.

As for the alias I suggested, if the particular pattern that has to occur at the start of intervening lines is quite common in your files, why not create a second alias just for that? Effectively, you’ve pretty much done that already with your existing regex; the alias given is more general-purpose, but could easily be slightly modified to be specific to your files, if common enough to be worthwhile.

If you find such expressions growing in complexity to the point where the search engine breaks on them, you can always write a short macro. This has the advantage of taking something that would require an involved regex to match and breaking it into two or more searches done procedurally. Check the documentation for the Find_Text() macro, which is the one you’d use for regex searches within macros. It’s quite useful. In creating such a macro, you’d basically be doing the same thing you’d do if you did the search by hand. Something like, find the opening pattern, mark the location, look for the closing pattern, and if you find it, mark a line block, then write a loop to step through each intervening line, checking that each fits the required pattern. After you’ve written one of these kinds of things, you’ll find yourself writing them for quite a few odd tasks that won’t quite surrender to a straight regex.