I'm using a regular expression search which is working as expected.
This searches for unified diff file entries and works as expected.
(re-search-forward
(concat
;; Prefix '+++ '.
"^"
"\\-\\-\\-[[:blank:]]+.*\n"
"\\+\\+\\+[[:blank:]]+.*\n"
;; May have trailing text which can be safely ignored.
"@@[[:blank:]]+.*[[:blank:]]@@")
nil t 1)
However some diffs have leading lines, eg:
// some context text.
diff --git a/my_source.c b/my_source.c
index 43484a57f1c..5985d498606 100644
--- a/my_source.c
+++ b/my_source.c
// some other context text.
My question is:
How can I include lines in the search which may or may not exist?
In this case: diff
and index
.
I tried this but it doesn't work, the \n
literals prevent the following ^
from being detected.
(re-search-forward
(concat
;; This fails :(
"\\(\\|^diff[[:blank:]]+.*\n\\)"
"\\(\\|^index[[:blank:]]+.*\n\\)"
;; Prefix '+++ '.
"^"
"\\-\\-\\-[[:blank:]]+.*\n"
"\\+\\+\\+[[:blank:]]+.*\n"
;; May have trailing text which can be safely ignored.
"@@[[:blank:]]+.*[[:blank:]]@@")
nil t 1)
How can these lines be included in the search if they exist, otherwise left as empty groups if they aren't present?