Ask Your Question
0

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

asked 2016-03-22 21:28:00 +0100

Montyj gravatar image

updated 2016-03-22 21:38:25 +0100

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.

Montyj

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2016-03-23 00:03:15 +0100

Lupp gravatar image

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).

edit flag offensive delete link more

Comments

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

"tree\."

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!

Montyj gravatar imageMontyj ( 2016-03-23 04:28:50 +0100 )edit
1

answered 2016-03-22 23:58:23 +0100

erAck gravatar image

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

edit flag offensive delete link more

Comments

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!

Montyj gravatar imageMontyj ( 2016-03-23 04:22:58 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-03-22 21:28:00 +0100

Seen: 199 times

Last updated: Mar 23 '16