* Bill McCarthy <[EMAIL PROTECTED]> writes: > I was playing around today with the Add Reference macro. The task of > adding the reference looks easy. But removing the references has been > surprisingly difficult.
> [...] Let's assume that either there is no In-Reply-To or > Reference lines OR they are both present with the Reference lines > immediately following the In-Reply-To line. > %SetPattRegExp="(?is)((.*\n)%- > In-Reply-To:.*?\nReferences:.*?\n%- > (?:\s.*?\n)*)%- > |((.*\n))%- > (.*)\n"%- > %RegExpBlindMatch="%Headers"%SubPatt="2"%SubPatt="4"%SubPatt="5" > %Text > If they exist, SubPatt 2 contains the header text before the > In-Reply-To line as expected. However SubPatt 5 is empty. Yes. Your Regular Expression is wrong. Read on. > I pasted the header to Vim editor session and typed the command: > s/\v((\_.*\n)In-Reply-To:.*\nReferences:.*\n%(\s.*\n)*)|((\_.*\n))(\_.*)/\2\4\5 > This worked perfectly. No, it didn't. The lines following the References: header stay untouched. That makes it look like it "worked perfectly" ;-) Add a few \5 at the end of the Vim command and you'll see that the result doesn't change. That means \5 is empty. Just like the empty subpatterns of your PCRE version in The Bat! This is it your version: > ((.*\n)In-Reply-To:.*?\nReferences:.*?\n(?:\s.*?\n)*)|((.*\n))(.*) || | | | | || ||| | |'----' '---------' | |'----'|'--' '---------------------------------------------------' '------' The priority of the vertical bar is lower than the priority of a ordinary concatenation of subpatterns. So your RE checks for "any text + In-Reply-To: line + References: lines (nothing more)" OR "any text (= patterns trailing the |)". That leads exactly to the results your are experiencing. Compare these two examples to see what I mean (the first one is like you did it, the second one is like you wanted it ;-) ,---- | %setpattregexp="(ab)(c)|(x)(def)" | %regexpblindmatch="abcdef" | %subpatt="0" -> abc | %subpatt="1" -> ab | %subpatt="2" -> c | %subpatt="3" -> | %subpatt="4" -> | | %setpattregexp="(ab)((c)|(x))(def)" | %regexpblindmatch="abcdef" | %subpatt="0" -> abcdef | %subpatt="1" -> ab | %subpatt="2" -> c | %subpatt="3" -> c | %subpatt="4" -> | %subpatt="5" -> def `---- And what you actually want is this: (((.*\n)In-Reply-To:.*?\nReferences:.*?\n(?:\s.*?\n)*)|(.*\n))(.*) ||| | | | | | ||| | ||'----' '---------' | '----'|'--' |'---------------------------------------------------' | '------------------------------------------------------------'[1] As a quick template: --8<---------------cut here---------------start------------->8--- %SetPattRegExp="(?isx) ( ( (.*\n) In-Reply-To:.*?\n References:.*?\n (?:\s.*?\n)* ) | (.*\n) ) (.*)\n"%- %RegExpBlindMatch="%Headers"%SubPatt="3"%SubPatt="5"%SubPatt="6" --8<---------------cut here---------------end--------------->8--- Uuuhhh, I really need recovery from using Vim... [1] drawing such lines without a free caret editor is horrible! -- Carsten ________________________________________________________ http://www.silverstones.com/thebat/TBUDLInfo.html
