Posted in the forum, but this probably should be filed as a bug too:
A journal requires page ranges 123--125 to be abbreviated page range 123-5
Using custom export filters I've tried Replace(regexp,replacewith), specifically
\format[Replace(--,-),Replace(1,Y)]{\pages}
That gives me 'Y23-Y25', but when I change this to
\format[Replace(--,-),Replace([1],Y)]{\pages}
nothing is replaced... As if RegEx doesn't work properly.
Various syntaxes are given for Replace() in http://jabref.sourceforge.net/help/CustomExports.php eg.
Replace(a,b) and Replace("a,b") and I've even tried (Replace("(a)","(b)") but all failed.
As soon as a in Replace(a,b) changes from a literal to a RegExp, Replace() fails.
Ultimate test pattern:
\format[Replace(^([0-9]*)([0-9]*)-(\1)([0-9]*),\1\2-\4]{\pages}
in TextWrangler, this RegExp pattern gives
2345-2347 -> 2345-7
2345-2357 -> 2345-57
2345-2447 -> 2345-447
2345-3347 -> 2345-3347
Hi,
I can confirm this bug. The problem is not in the Replace formatter itself, which basically runs your arguments through the JabRef regexp processor. The problem originates with the parsing of the arguments, probably because of the square brackets that conflict with the delimiters for the formatter name(s). I expected this could be handled by escaping the brackets, but that doesn't seem to be the case. I need to look more closely into the code to find out more, but for now I believe you can only make the replace work if your regexp doesn't use square brackets.
I have now committed a fix for this in our Git master branch. You will need to use quotes around the replace parameters (inside the parentheses) - the quotes are optional, but you need them when the arguments include brackets. This only works properly after today's fix.
In addition, you need to adjust your replacement string to use $1 instead of \1 to insert groups. The correct layout statement will be as follows:
\format[Replace("^([0-9]*)([0-9]*)-(\1)([0-9]*),$1$2-$4")]{\pages}
This works for me now. If you want a test version from our master branch (development version) I can provide it.
Upon release 2.8.2, this shoud probably be mentioned in the help page
http://jabref.sourceforge.net/help/CustomExports.php
to prevent a lot of frustration with examples not matching reality (also mention 'scince 2.8.2' there?)