I’m trying to de-LaTeX a document that Pandoc choked on. The document is now in Scrivener. I’m trying (at least at this stage) to replace \section with # for easy conversion to Markdown. However, when I try to convert using Project Replace, I get the following ‘not found’ error:
Find: #{
Replace with: #
So Scrivener isn’t seeing the bracket–or maybe the crosshatch as well.
Another somewhat related issue: I need to remove all of LaTeX’s index entries. These are in the format \index{Labor Law!Employment Contract!writing}. The text in the brackets changes based on the index entry. I would like to remove all of these entries–they are not on separate lines, either. Maybe there’s an awk or sed way of doing this, if I can’t do it from within Scrivener.
Yes, curly-brackets are special characters in regex syntax, used as quantifiers. The pattern, if properly formed, would be something like #{1,6} where that would mean “look for one to six hashmarks in a row”. #{ is meaningless, a syntax error.
As the forum uses Markdown itself, yes you do need to escape special characters with a \ character:
#
Sounds good though, you just need the pattern to be valid, which @drmajorbob describes how to do. \{ tells regex to look for that symbol itself, not use it as syntax.
That said, I see a bug in Project Replace where if you use regex mode and select fields in the lower part that might be empty, it throws an internal error that you won’t see unless you have internal error alerts enabled. It should be skipping over empty fields (like custom metadata or synopsis) rather than passing empty data to the regex engine, it looks like. If you don’t see error alerts, then it will just silently fail, and lead you to believe there is a problem with the search parameters, when in fact it would fail no matter what you type into the replace/with fields.
Assuming what you’re really looking for is #{Name of Thing} and want that turned into # Name of Thing, then this pattern works:
Replace: ^#\{([^}]+)\} With: # $1
(If you’re wondering, you often do not have to escape special characters inside of a range: [^}]+ means one or more characters that aren’t “}” specifically.)
Well, in this case it is not so mysterious. You usually only need to escape characters that mean something in Markdown. #24 is not Markdown, nor is talking about the character ("#") in passing.
But put it at the beginning of a line? Well now, that…
Means Something
The same is often true elsewhere, like in our regex example above. A curly-bracket after a character like that is most definitely syntax (incomplete in this case). But this same character inside of a [^...] range is just a character, because the interior of a range uses a different and much simpler syntax than regex.
When in doubt, escape. Most systems will not choke on over-use of escaping. You can’t see it here, but this: # is escaped, even though there is no need to do so.