miscellaneous search/replace regular expressions I've used recently in TextPad
Here are some miscellaneous search/replace regular expressions I've used recently, that seemed worth keeping (to me). I used these in TextPad with the option in Configure Preferences Editor, called "Use POSIX regular expression syntax", checked. Sometimes I find that TextPad's search/replace functionality is more useful to for a particular purpose than 'sed' in unix/cygwin. Other times I use sed and stuff. That's the beauty if cygwin, I can mix and match windows and unix whenever I want (as some previous and near future posts will show).
These are mostly presented in the format:
Line 1: short description of search/replace expressions
Line 2: regex to search for
Line 3: replacement expression
change from (myMaybeNullFunc().equals("myStaticString") to ("myStaticString".equals(myMaybeNullFunc())
([\(]*)([a-zA-Z\.\(\)]+).equals\("([^"]+)"\)
\1"\3".equals(\2)
change from (myMaybeNullVar.equals("myStaticString") to ("myStaticString".equals(myMaybeNullVar)
([^a-zA-Z])([a-zA-Z]+).equals\("([^"]+)"\)
\1"\3".equals(\2)
change from myResultSet.getString("foo") to myObject.getFoo()
myResultSet\.get[A-Z][a-z]+\("([^_"])([^_"]+)"\)
myObject.get\u\1\2()
change from myResultSet.getString("foo_bar") to myResultSet.getString("FooBar")
rs\.get([A-Z][a-z]+)\("([^_"])([^_"]*)_([^_"])
rs.get\1 ("\u\2\3\u\4
(run this one repeatedly until no more matches, then run the one above it)
change HTML start tags to upper case
<(\<[[:word:]]*\>)
<\U\1
change HTML end tags to upper case
</(\<[[:word:]]*\>)
</\U\1

0 comments:
Post a Comment