I have this line in a Lua script that crash my software every time:
fmt_url_map = string.gsub( fmt_url_map, '%2F','/' )
I want to replace all occurrences of %2F occurrences in a text to /.
If I remove the % , it doesn't crash.
What am I doing wrong ?
% is a special symbol in Lua patterns. It's used to represent certain sets of characters, (called character classes). For example, %a represents any letter. If you want to literally match % you need to use %% .
You can do this by using %% in the printf statement. For example, you can write printf(“10%%”) to have the output appear as 10% on the screen.
Valid in Lua, where %w is (almost) the equivalent of \w in other languages. ^[%w-.]+$ means match a string that is entirely composed of alphanumeric characters (letters and digits), dashes or dots.
Instead of using regex, the Lua string library has a special set of characters used in syntax matches.
% is a special symbol in Lua patterns. It's used to represent certain sets of characters, (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 Manual for more information. I suspect you're running into problems because %F is not a character class.
You need to escape the '%' with another '%'
fmt_url_map = string.gsub( fmt_url_map, '%%2F','/' )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With