I had a draft with several lines of text that had been pasted in from another source. Many of the lines had trailing spaces (one or more), and I wanted to delete them via find-and-replace. The straightforward regular expressions to do this,
found only the last line in the draft. And if I altered the Find regex to
it wouldn’t find anything at all.
After some experimentation, I learned that the anchors
$ refer to the beginning and end of the draft as a whole, and not to the beginning and end of each line in the draft. This contradicts the NSRegularExpression documentation that Greg links to on the Drafts Find and Replace page.
In fact, the example on the Find and Replace page—where first and last names are reversed—doesn’t work as described. It reverses only the names on the first line of the draft, not all of the lines.
Am I missing some regex flag that needs to be set to get the anchors to work on a line-by-line basis, or is the documentation out of sync with the current implementation?