I am currently working on some legacy code (java project), and a lot of variables (15k) have an underscore as their first char, e.g:
_iAmAInt //should be iAmInt
(all variables to be replaced start with _ followed by a lower case letter)
So i thought i would try to clean this using a small script, with sed and regex, so far this is what I've got:
while IFS= read -r -d '' file; do
if [[ $file == *.java ]]; then
sed -i -E 's/([_])([a-z])/\2/g' $file
fi
done < <(find "$1" -type f -print0)
The thing is in some cases, I have some strings (for example queries) which have something like this: "select house_id from houses"
My current regex doesn't take this into account, but obviously I need to specify somehow that the _ that are between " " are not be to be deleted.
From what I've read, I could use a negative lookahead (Regex: match everything but specific pattern)
But I'm not quite sure this would solve completely my issue, or even if the whole process is a good idea ?
Any hints or feedbacks, on how to proceed and what to do or not are welcome ! Thanks
Edit: Yes the code is Java, and SonarQube flags this is as an issue (even though, it's not really critical)
Edit 2: Thanks for all the answers and comments, I've learned a lot, I'll try them out and make sure to choose one as a valid answer !