[SalesForce] FIND {query} with special characters failing with ampersand

FIND {tim/?jacob} parses perfectly fine when running the query.

FIND {tim/&jacob} gives the following error:

line 1:10 mismatched character '&' expecting '}'`

what am I doing wrong?

According to Salesforce Developer Docs, the ampersand is possible to escape, as it is included in this list:

Escaping special characters & | ! ( ) { } [ ] ^ " ~ * ? : \ '

EDIT:

I used the wrong slash, which explains the above error.
When changing to FIND {tim\&jacob} as per the documentation, I get this parsing error.

Invalid string literal 'FIND {tim\&jacob} IN ALL FIELDS RETURNING '. Illegal character sequence '\&' in string literal.

When changing to FIND {tim\\&jacob}, I do not get an error, but the query is parsed as FIND {tim\&jacob} when I return it to me, and this returns 0 results.

Best Answer

I was able to figure this out by ignoring the documentation.

Find \' Tim&Jacob \' actually did the trick, with no escapes.

Since my string is actually held in a variable, here is my final code.

searchStr = 'Tim&Jacob';
String searchQuery = 'FIND \'' + searchStr + '\'';