9fans archive / 2008 / 10 / 360 / prev next From: Charles Forsyth <forsyth@ter...> Subject: Re: [9fans] non greedy regular expressions Date: Fri, 24 Oct 2008 23:54:50 +0100 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/