How to search for metacharacter "\" in a function?

I am trying to locate the position of the a string within a string that contains a backslash character “” in a cell. Example:

String to be searched: “mobi”

I am trying to get the position of this string using the FIND function. Example:

FIND("mobi\\";a1;) does not work; #VALUE! error.

Note: The position of “mobi” in the string varies, so cannot use the 3rd ‘position’ value. Also I cannot use just the string “mobi” because the string “mobile” is present and needs to be ignored.

Thank you.


FIND does not support regular expressions, but SEARCH does. So either use FIND("mobi\";A1) or use SEARCH("mobi\\";A1)

Well, I am a little red-faced over this! I had tried both you examples and neither worked as part of a much more complicated statement with many functions. Then I tried a simple test in a blank cell and they would not work there either as single function calls. I just tried that again and they do indeed do work as single function statements. In the meantime I found a workaround using a forward slash where the backslash would not work. Don’t know why the backslash did not work the first time!

You obviously expected your search string to be taken as a regular expression (RegEx) and therefore “escaped” the backslash from being treated as a special character by a second one. If your setting is ‘Enable regular expressions in formulae’ this actually is needed when working with SEARCH. FIND, however, will take any string as a string of literals (and is case sensitive in addition).

Please see my comment above. And yes, the regex use came from LO’s online documentation. They use the example of searching for “tree.” In this case they showed the example of ‘escaping’ the dot as


So I took that and ran with it, giving a backslash to ‘escape’ the backslash. As I said above, for some reason single or double did not work with FIND. Now I know why double didn’t work!