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}
\addbibresource{\jobname.bib}
\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? :)

replacemapping option? – Guido Nov 22 '12 at 0:14:)In my real file, I have different keys forfieldsourceandfieldset, 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 usereplace, both keys have their values changed, and not only the one pointed byfieldset. I'm not sure if I'm using this feature correctly, butfieldvaluegave me the correct attribution.:)– Paulo Cereda Nov 22 '12 at 0:27\DeclareStyleSourcemap. This way you don't have to worry about the user-level\DeclareSourcemapoverriding all of your mapping rules. – Audrey Nov 30 '12 at 19:06\DeclareStyleSourcemap.:)– Paulo Cereda Nov 30 '12 at 19:07