Quote:
Originally Posted by Manichean
If I understood the matter correctly, you need to escape the backslashes for the search parser in order for them to stay in place as a single backslash for the regex parser.
|
You have it right.
Backslashing things is always a problem because the backslash is often used to 'escape' other special characters by each piece of the processing chain. In calibre, there are two such pieces: the search language parser and the search engine. Each will process backslashes.
The string passed to search is first processed by the search language parser. Backslashes are used as escapes: for example a \" means that the quote is part of the query and not the end of a query segment. Following fairly universal rules, all escaping backslashes are removed after processing. As such, \w is processed, determined to mean 'w', and the backslash is removed. The result is passed to the search engine, where additional escape processing is done, for example for regular expressions.
Because of the dual processing, if you want to pass a real backslash to the search engine, you must escape it using a doubled backslash. Thus \\w instead of \w.