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


September 14th, 2007 at 4:58 pm
[…] preferences, I have it set to Use POSIX regular expression syntax (as previously mentioned, in another TextPad search/replace expression entry, a couple years […]
September 15th, 2007 at 7:34 am
1) You gotta love cygwin. Why deal with Unix when you can have the tools run under windows? (NOTE: I’ll probably feel differently in 10 years because windows is going downhill!)
2) I know the feeling of “run this one repeatedly until no more matches”, hehe. It’s kinda fun.
3) What a messed up search-and-replace. So you have to do “string”.method, as if the static string is an object with a method? I understand that that’s how it may actually work underneath the hood, but that’s counterintuitive. I’d rather do it the original way you had it :)