I am adding divider lines to certain sections of the reports generated by the binary ledger
[ https://www.ledger-cli.org/ ] through the function ledger-do-report
in the ledger-mode
Lisp library [ https://github.com/ledger/ledger-mode]. To accomplish this goal, I have chosen replace-regexp-in-string
. I wish to prepend the divider line followed by a new line; i.e., "======\n"
.
Q: Is there a built-in way to prepend the additional string without the need to create an empty substring at the beginning of the REGEXP; i.e., \\(\\)
?
In the following example, I have begun my REGEXP with ^\\(\\)
so that I can replace that number 1 subsexpression with the new string. However, I have a feeling that there is a more correct approach to simply prepend a string without using an empty placeholder in the REGEXP.
NOTE: The ^[
is defined by Emacs as: old-name: ESCAPE; general-category: Cc (Other, Control); decomposition: (27) ('^[')
;;; $ 98,477.47 ASSETS
;;; =>
;;;
;;; $ 98,477.47 ^[[34mASSETS^[[0m
;;;
(setq report (replace-regexp-in-string
"^\\(\\)[\s]+$[\s]\\([0-9,.]+\\)[\s]+^[\\[34m\\(ASSETS\\)^[\\[0m$"
(concat (make-string (- (window-width) 1) ?=)" \n")
report nil nil 1))
"\e"
for the ESCAPE char, and then people can copy/paste the code.