This is now a follow-up to Prevent abbreviation of names for anonymous work with biblatex, itself a follow-up to Abbreviate resolved abbreviations in authors' first names in biblatex.
In short, I need to print the names of the authors as they appear in their own original work. In my .bib file, on the other hand, I always supply the missing information about names within brackets. The trick is therefore to delete this extra information in appropriate ways.
Now, using the code from Andrew Swann's answer to my question, I notice that when I have an entry in my .bib file in which the author's first name is missing, yet supplied in brackets, the output prints the author's last name followed by a comma plus white space plus a period, because the code has abbreviated a first name into an empty white space character:
Lennon, . (1974).
The appropriate output would be one that just prints the last name: Lennon (1974). The other names should appear as they do in this MWE.
Any suggestions?
\documentclass{article}
\usepackage[style = authoryear-comp]{biblatex}
\DeclareSourcemap{\maps[datatype = bibtex]{
\map{
\step[fieldsource = author, notmatch = \regexp{\A\[.+\]\Z}, final]
\step[fieldsource = author, match = \regexp{\[[^]]+\]}, replace = .]
}
\map{
\step[fieldsource = author, match = \regexp{\A\[(.+)\s+([^\s]+)\]\Z},
replace = {[$2, $1]}]}
}}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{lennon1970,
AUTHOR = "J[ohn] Lennon",
TITLE = "My life with the Beatles",
YEAR = "1970",
SORTNAME = "John Lennon"}
@BOOK{lennon1971,
AUTHOR = "[John Lennon]",
TITLE = "Moving on",
YEAR = "1971",
SORTNAME = "John Lennon"}
@BOOK{lennon1972,
AUTHOR = "[J. John Lennon]",
TITLE = "Moving further on",
YEAR = "1972",
SORTNAME = "John Lennon"}
@BOOK{lennon1973,
AUTHOR = "John Lennon",
TITLE = "Still moving on",
YEAR = "1973",
SORTNAME = "John Lennon"}
@BOOK{lennon1974,
AUTHOR = "[John] Lennon",
TITLE = "I'm out of here",
YEAR = "1974",
SORTNAME = "John Lennon"}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

EDIT
Applying moewe's suggestion below, something goes wrong when there is more than one author with brackets in the AUTHOR field.
\documentclass{article}
\usepackage[style = authoryear-comp]{biblatex}
\DeclareSourcemap{
\maps[datatype = bibtex]{
\map{
\step[fieldsource = author, match = \regexp{\A\[(.+)\s+([^\s]+)\]\Z}, replace = {[$2, $1]}]
}
\map{
\step[fieldsource = author, match = \regexp{(\w+)\[(.+)\]}, replace ={$1.}]
}
\map{
\step[fieldsource = author, notmatch = \regexp{\A\[(.+)\]\Z}, final]
\step[fieldsource = author, match = \regexp{(\A|\,\s)\[(.+)\]}, replace = {}]
}
}
}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@BOOK{lennon1970,
AUTHOR = "J[ohn] Lennon",
TITLE = "My life with the Beatles",
YEAR = "1970",
SORTNAME = "John Lennon"}
@BOOK{lennon1971,
AUTHOR = "[John Lennon]",
TITLE = "Moving on",
YEAR = "1971",
SORTNAME = "John Lennon"}
@BOOK{lennon1972,
AUTHOR = "[J. John Lennon]",
TITLE = "Moving further on",
YEAR = "1972",
SORTNAME = "John Lennon"}
@BOOK{lennon1973,
AUTHOR = "John Lennon",
TITLE = "Still moving on",
YEAR = "1973",
SORTNAME = "John Lennon"}
@BOOK{lennon1974,
AUTHOR = "[John] Lennon",
TITLE = "I'm out of here",
YEAR = "1974",
SORTNAME = "John Lennon"}
@BOOK{lennon1975,
AUTHOR = "Lennon, [John]",
TITLE = "I'm out of here",
YEAR = "1975",
SORTNAME = "John Lennon"}
@BOOK{beatles1970,
AUTHOR = "John W[inston] Lennon and J[ames] Paul McCartney",
TITLE = "Let it be",
YEAR = "1970"}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}


.bibfile, I do not want the brackets removed. In my example, then, I only want to fix theLennon, . (1974).entry toLennon (1974).Everything else should stay the way it is. (If you manage to find a solution to this, please just add it to your existing answer, which I think migth be useful on a later occasion as well:)) – Sverre Aug 12 '15 at 16:03$1in the third map). You may want to try the new solution. – moewe Aug 12 '15 at 17:12