1

The "Advanced Search" Org mode tutorial on Worg provides the following example to find all entries with either "Walter" or "Evensong" in the author field:

BIB_TITLE={Walter\|Evensong}

I would like do the same in a custom agenda command. However the following produces a syntax error:

 (setq org-agenda-custom-commands
    '(("q" tags "BIB_TITLE={Walter\|Evensong}")))

Can you suggest a correct method? I do not need to use a regular expression per se, the above example was the only one I could find.

NickD
  • 27,023
  • 3
  • 23
  • 42
Snelephant
  • 814
  • 1
  • 7
  • 17

1 Answers1

0

You have to precede a backslash with another backslash to include it in a string. The correct syntax should be:

 (setq org-agenda-custom-commands
    '(("q" tags "BIB_TITLE={Walter\\|Evensong}")))
Programator2
  • 148
  • 6
  • Programator2's suggestion works without error. However, the resulting agenda includes no matches. Is there additional consideration if the property values contain whitespace? Specifically, my property values are `"Five-year plan"` and `"Two-year plan"` and my syntax following Programator2's suggestion is `("q" tags "LongTermPlan={\"Five-year plan\"\\|\"Two-year plan\"}")`. This parses without error, but returns no matches. Interactive search in agenda view using the same property values works, so the property values are valid. It fails only when using the regular expression above. – Snelephant Feb 08 '23 at 18:43
  • I'm guessing that quotation marks are not part of the property values. If so, they shouldn't be in the regexp: `("q" tags "LongTermPlan={Five-year plan\\|Two-year plan}")`. – Programator2 Feb 08 '23 at 20:44
  • Removing the quotation marks within the regular expression solved the problem and returned the desired matches. I had enclosed property values in quotation marks following the worg tutorial on [custom agenda commands](https://orgmode.org/worg/org-tutorials/org-custom-agenda-commands.html). Note Programator2 provides solutions to two separate issues that could occur in custom agenda commands when using regular expressions to match property values: 1. Precede a backslash with a backslash to include it in a string. 2. It is not necessary to enclose property values in quotation marks. – Snelephant Feb 09 '23 at 05:12