# Concatenating regex variables in fieldvalue

Friends, I'm stuck with a doubt about how to concatenate values from regex parenthesis into the fieldvalue mapping option. Let's see a quick working example:

\documentclass{article}
\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib}
@book{fruits,
title = {The apple and the banana},
publisher = {Tomatopress},
editor = {Straw Berry},
author = {Annoying Orange},
year = {1970}
}
\end{filecontents*}

\usepackage[utf8]{inputenc}
\usepackage{biblatex}

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\step[fieldsource=title,
fieldset=title,
match=\regexp{(\w+)\s+(\w+).*},
fieldvalue={$1} ] \step[fieldset=title, fieldvalue={~$2},
append
]
}
}
}

\begin{document}

Hello world \cite{fruits}.

\printbibliography

\end{document}

The idea here is quite simple: get the first two words of the title key, in my case, $1 = The and$2 = apple. The output is as expected:

Note that in my code I used two \step's: one setting fieldvalue to $1 and the other appending$2 (preceded by a non-breaking space) to it. I was hoping to save a step and try the following code (preferably I'd prefer a breakable space):

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\step[fieldsource=title,
fieldset=title,
match=\regexp{(\w+)\s+(\w+).*},
fieldvalue={$1~$2}
]
}
}
}

but it doesn't work. I know I could use the replace mapping option - actually, this MWE is too simple - and the expansion of those two variables work, but for the project we are working on, we have to use fieldvalue. I was wondering how can I add an arbitrary number of variables in a fieldvalue all at once instead of incrementally using \step's to append the values.

Any ideas? :)

-
Can you expand why you cannot use the replace mapping option? –  Guido Nov 22 '12 at 0:14
@Guido: Sure! :) In my real file, I have different keys for fieldsource and fieldset, where regex is applied to the value of the first key and then the result is stored in the value of the second key. If I use replace, both keys have their values changed, and not only the one pointed by fieldset. I'm not sure if I'm using this feature correctly, but fieldvalue gave me the correct attribution. :) –  Paulo Cereda Nov 22 '12 at 0:27
@PauloCereda If this is for a custom style, consider upgrading to 2.4, where Philip has introduced \DeclareStyleSourcemap. This way you don't have to worry about the user-level \DeclareSourcemap overriding all of your mapping rules. –  Audrey Nov 30 '12 at 19:06
@Audrey: Thanks a million for the hint, Audrey! I'll take a look at \DeclareStyleSourcemap. :) –  Paulo Cereda Nov 30 '12 at 19:07

This is a bug in biber 1.3. Please try version 1.4 from Sourceforge. You'll also need to be using the biblatex 2.4 beta from SourceForge. You might also want to wrap the $1~$2 in \regexp{} to stop biblatex turning the ~ into \nobreakspace {} if it matters to you (the fieldvalue is sanitised specially because it ends up as an XML attribute in the biber .bcf file).