You cannot use Percent (%) in a Lua template

I have this line in a Lua script that breaks my software every time:

fmt_url_map = string.gsub( fmt_url_map, '%2F','/' ) 

I want to replace all occurrences of %2F occurrences in the text with / . If I remove%, this will not work.

What am I doing wrong?

+7
source share
2 answers

% is a special character in Lua patterns. It has been used to represent specific character sets (called character classes). For example, %a represents any letter. If you want to literally match % , you need to use %% . See this section of the Lua Reference Guide for more information. I suspect you are having problems because %F not a character class.

+12
source

You need to escape "%" with another "%"

 fmt_url_map = string.gsub( fmt_url_map, '%%2F','/' ) 
+6
source

All Articles