Find Text Position with Special Characters

I’m having trouble find text that have special characters such as & or apostrophe. For example if I want to find the text “Johnson & Johnson” or “McDonald’s” using the Find Text Position activity, then it will throw an error. The text is stored in a string variable so I’m just putting the name of the variable for the activity. Anyone know how to handle special characters?

Welcome to the forum

Maybe it is an option for you to change the implementation in a combination with get text and Regex

  • retrieve the text with get text
  • retrieve the position in string with Regec.Match…

find some starter help here:
RegEx_MatchPositionInString.xaml (6.3 KB)


Johnson & Johnson is just an example. I don’t know what the text will be ahead of time. That’s why it’s stored in a variable when I’m using the Find Text position activity. The text can be anything. It is read from a database where the data changes every day. For example, I need to find the position of the UI element on the screen that reads “Johnson & Johnson”. But the Find Text position throws an error when the text has special character like & or apostrophe. It works fine with just regular alphabet characters. I hope that’s a better explanation.

@ppr’s explanation still works regardless of the word you include, just use the variable or datatable.item or whatever you were planning on using. Just switch his answer so intstead of the literal “Johnson & Johnson” you can substitute for your variable. I would also surround it in a regex.escape(). So if you stored the string you want to search in a variable called StringToFind, your expression to find the index would be: Assign TextPosition = regex.match(strText,regex.escape(StringToFind))(0).index

Thanks. Well I find out that I can wrap curly braces around the variable to include special characters and that doesn’t cause an error when finding the text position, like this: {{variableName}}