Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

my code is right but Lua replace doesn't working (:gsub)

Hello I am trying to replace a specific text to "" and my code doesn’t working. I just don’t know why my code not working

b = 'Just testing.<script>window.location.replace("http://google.com");</script>'
print(b)
b = b:gsub('<script>window.location.replace("http://google.com");</script>', "")
print(b)

out 1: Just testing.window.location.replace("http://google.com&quot;);
out 2: Just testing.window.location.replace("http://google.com&quot;);

I tried b = string.gsub(b,'<script>window.location.replace("http://google.com");</script>',"") too but its doesn’t worked either

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am working in FiveM

>Solution :

You need to escape ( and ), in a lua pattern they are recognized as special character. you can escape them using %

b = 'Just testing.<script>window.location.replace("http://google.com");</script>'
print(b)
b = b:gsub('<script>window.location.replace%("http://google.com"%);</script>', "")
print(b)

For more infomration on lua patter you can look at these resources:

Understanding Lua Patterns

20.1 – Pattern-Matching Functions

20.2 – Patterns

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading