I have a bibtex file (produced by jabref) and I would like to remove the linebreaks in the fields, e.g.,
@INPROCEEDINGS{Sims1994b,
author = {Sims, K.},
title = {{Evolving 3D Morphology and Behavior by
Competition.}},
booktitle = {{Proceedings of the 4th International Conference on
Artificial Life}},
pages = {28--39},
year = 1994
}
should become
@INPROCEEDINGS{Sims1994b,
author = {Sims, K.},
title = {{Evolving 3D Morphology and Behavior by Competition.}},
booktitle = {{Proceedings of the 4th International Conference on Artificial Life}},
pages = {28--39},
year = 1994
}
unfortunately my regexp-fu is not up to the task :-)
For the example you gave, this does the job:
M-x query-replace-regexp
RET \({[^=},]+\)^J +
RET \1
RET
I couldn't figure out how to force the SO formatter to include it, but the \1
should be followed by a space, as "Competition" and "Artificial" will be glued to "by" and "on" if you omit it.
Also note that ^J
represents a quoted insertion of a newline (but from your comment above I assume you already know that that's produced by issuing C-q C-j).
The \1
in the replacement text is a back reference to the first parenthesized group. This tells Emacs to include the content that matches the portion of the regexp between the \(
and \)
in the replacement string (and discard/overwrite everything else).
In case you're not already familiar with it, re-builder is an excellent (built-in!) tool for building up regexps incrementally.