How to escape a string so it does not get replaced by Token::replace() I have a string that is being sent into the replace method of the token service that looks like a token, but it is not. 

Here is an example of the string: "['key:value']"

Is it possible to escape this in a way that the replace function will not think it is a token that it needs to replace? 

The "clear" flag in the replace function is set to true, so this string always just gets removed, but I want it to ignore this string entirely. Thanks!
Token::replace() allows you to use a callback to replace extra tokens no module define, but that is called after the tokens have been replaced; plus, it gets a array as array($original_token =&gt; $replacement) which makes things slower since you would need to replace each token one by one.

I would rather set 'clear' to FALSE, and then replace all the tokens that have not been replaced with an empty string. Since the strings you need to keep follow a specific pattern, it would be easier to remove the unreplaced tokens with preg_replace().