I need to modify the keys of a key value file as follows:
"1Don't do that" = "some value"
to
"_1Don_t_do_that" = "some value"
I can do it in several steps if necessary
I've tried things like \"\w+[^\w]\w+\" =
but it doesn't account for multiple spaces and does not single or double quotes.
Any help is welcome.
Assuming that none of your quotes are escaped, this should work:
(?:(?<=")(?=\d)|[^\w"])(?=[^"]*"\s*=)
This matches
"
and a digit but only if they are followed by a single quote and an equals sign.
See it live on regex101.
I’m not sure what regex flavor Xcode uses, but as long as it supports positive lookahead (?=)
, this series of replacements should work:
^"(?=\d)
"_
[^a-zA-Z0-9](?=[^"]*"\s*=\s*"[^"]*")
_
The second step assumes that quote characters never occur in the value string; tell me if you need to handle backslash-escaped quote characters.
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