There's several things wrong with that at first sight.
1. You only check for =
In your test data you seem to have cases with key = value as well as key : value but your pattern only checks for =
; replace that with [=:]
for a simple fix.
2. You can't balance quotation marks
I don't know how you expect this to work, but [[%b""]]
just finds the shortest possible string between two "
characters, just as [[".-"]]
would. If that's your intention, then there's nothing wrong with writing it using %b
though.
3. Just don't
As I don't know the context, I can't say if this really is a bad idea or not, but it does seem like a very brittle solution. If this is an option, I would recommend considering the alternative and going with something more robust.
As for what a better alternative could look like, I can't say without knowledge of your requirements. Maybe normalizing the data into a Lua table and replacing the password
key in a uniform way? This would make sure that the data is either sanitized, or errors during parsing.
Beyond that, it would help if you told us how it doesn't work. It's easy to miss bugs when reading someone elses code, but knowing how the code misbehaves can help a lot with actually spotting the problem.
EDIT:
4. You didn't even remove the brackets
You didn't even remove the []
from that other stack overflow answer. Obviously that doesn't work without any modifications.