From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: From: Charles Forsyth Date: Fri, 24 Oct 2008 23:54:50 +0100 To: 9fans@9fans.net In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [9fans] non greedy regular expressions Topicbox-Message-UUID: 27146b72-ead4-11e9-9d60-3106f5b1d025 although it can be satisfying to do things in one instruction (one command) i confess i often find it quicker to split up the problem in sam or acme: 1. delete everything not between delimiters ,y/ABC([^C]|C[^B]|CB[^A]|\n)+CBA/d 2. delete the delimeters ,x/ABC|CBA/d 3. look to decide if i missed a boundary case for my input it would be easier if the delimiters weren't words, or your sections didn't span lines. i didn't spend any time deciding whether there was a better way to express the trailing word delimiter. it's too late. an example actually using the () [submatch] to extract and exchange two fields on each line: ,x s/([^,]*),(.*)/\2,\1/