This is a follow-up to the question Can't replace non-ascii characters with biblatex. The aim is to replace certain character strings in .bib file entries with other strings.
Compiling the following document now works fine in xelatex:
\documentclass{article}
\usepackage[style = authoryear-comp]{biblatex}
\usepackage{fontspec}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{lennon1968,
AUTHOR = "John Lennon",
TITLE = "xåy",
YEAR = "1968"}
\end{filecontents}
\DeclareSourcemap{
\maps[datatype = bibtex]{
\map{
\step[fieldsource = title,
match = \regexp{xåy},
replace = {abc}]
}
}
}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

But when I use the common macro \aa instead of å, it fails:
\documentclass{article}
\usepackage[style = authoryear-comp]{biblatex}
\usepackage{fontspec}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{lennon1968,
AUTHOR = "John Lennon",
TITLE = "x{\aa}y",
YEAR = "1968"}
\end{filecontents}
\DeclareSourcemap{
\maps[datatype = bibtex]{
\map{
\step[fieldsource = title,
match = \regexp{xåy},
replace = {abc}]
}
}
}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

Apart from replacing macros like \aa in my .bib file with UTF-8 characters like å, is there any way to overcome this problem?
\regexpand white space. My.bibfile has something likefoo x{\aa}y bar, and my.styfile has\regexp{foo x{å}y bar}. This won't work. Any solution? (I want to use\regexpbecause I'm replacing many different strings with one string. e.g.\regexp{(foo x{å}y bar)|(bar foo)|(no foo bar)}. – Sverre Sep 02 '14 at 16:16.bcffile to for examplemap_match="foo x\{å\}y bar"then all is well ('ve escape the{}pair to be on the safe side). However, spaces in the regex at the LaTeX end don't get passed on correctly. I'll have to look at that separately! – Joseph Wright Sep 02 '14 at 16:41\let\regexp\detokenizebefore the source map. If that works for you, should I write up an answer? – Joseph Wright Sep 02 '14 at 16:45\let\regexp\detokenizebefore\DeclareSourcemap, because that messes up other things I do withregexp. Instead I put it after\map{. Please feel free to add an answer (but remember that it should also answer the original question, not just the stuff we've discussed in the comments here). – Sverre Sep 02 '14 at 17:05