I was making a macro to manipulate some text using BBEdit and had the worse time getting a Grep search to work. Finally figured out that whether using type text or paste text KM was not willing to paste something like
^(.*)(\d{2}/\d{2}/\d{4})(,.*,)(.*\$)
Shows up in BBEdit in the Search dialog or just a plain text file as
^(.*)(\d{2}/\d{2}/\d{4})(,.*,)(.*$)
Hopefully this can help others as I killed an hour trying to figure out why my Grep would work fine in the BBEdit Pattern Playground but wouldn't work when I took the same search and had it typed in using the macro. Never expected a dropped backslash only when used with $ with all the \d going through fine.
Edited to add tics to code and point out that why it was hard to find.
I guess. What made it hard is that all the slashes kinda ran together and I just couldn't see it getting dropped. Plus some of the slashes were ok (\d). If all the slashes needed to be escaped then it would have been much more noticeable.
Somewhat surprising it would manifest itself when just trying to have KM paste or type some text. Still can't find where it is referenced in the manual.
Good point! @peternlewis, can you please enlighten us as to why the double backslashes are needed sometimes but not others? Is there a rule? If so, where?
If we are talking about a text field, then many text fields (like Insert Text) have an option to control the processing:
Process Text Normally
Process Text Tokens Only
Process Nothing
The default, unsurprisingly, is Process Text Normally, except in regular expression fields where it is Process Text Tokens Only.
Processing text processes the normal text tokens (eg %LongDate%) as well as backslashed characters like \n for linefeed. The latter processing is omitted when Process Text Tokens Only is selected.
When backslashed characters are processed, the various characters that have meaning are replaced with the corresponding characters. The characters that have meaning after a backslash are shown in the Tokens page.
For characters that have no meaning (such as “d” in this context), \d is unchanged, so the result is \d.
The simplest solution if you don't want this processing is to switch the processing to Process Text Tokens Only or Process Nothing. Otherwise you should quote every backslash by doubling it (\d results in \d, but so does \\d, whereas \t results in tab while \\t results in \t).
Agree already switched all of them. Was hoping to figure out a heads up for people not on this thread that would be searchable on wiki or here.
As I am a simple person, "normal processing" an input text action seems akin to using TextEdit/BBEdit for text input. Nothing fancy to worry about just pasting/typing the text in the box to an application. Having it sometimes process (\s) and sometimes not (\d) is, to me, confusing for a "normal processing" default text input action preference.
It's documented on the Tokens page I linked to, but it is subject to change at any time and frankly there is never any reason to ask this question. You should assume backslash of a letter means something, and not use it if that is not what you want. Otherwise future changes may break your macro. It has changed multiple times in the past and definitely will in the future since \v was just added and has not been released yet, so the Tokens page is correct currently but will be incorrect in the near future.
Backslash the Backslash if you want the Backslash to have no meaning. Or use the control to turn off processing.