Skip to content

Instantly share code, notes, and snippets.

@shawnjgoff
Created August 30, 2012 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnjgoff/3543601 to your computer and use it in GitHub Desktop.
Save shawnjgoff/3543601 to your computer and use it in GitHub Desktop.
replace python's depricated dict.has_key(k) with "k in dict" with a regex
Vim regex
:%s/\([^ ]\+\)\.has_key(\(.\{-}\))/\2 in \1/g
sed regex
s/\([^ ]\+\)\.has_key(\([^)]*\))/\2 in \1/g
And here is the string.method(object, ...) -> object.method(...)
Specificlaly for string.replace():
Vim regex:
%s/string\.replace(\(.\{-}\), /\1.replace(/
sed regex:
s/string\.replace(\([^,]*\), /\1.replace(/
string.method(object) -> object.method()
Specifically for string.lower():
sed regex:
s/string\.lower(\(.*\))/\1.lower()/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment