Regular expressions is a great way to find those hard to find strings.
Suppose you have a bunch of old code and you want to bullet proof it or you might be interested in auditing it and for starters you want to find those uninitialized variables using eclipse.
the pattern of uninitialized variable could be in the following format
(Var)(space or more)(Alphanumeric word)(Possible space or more)(semi-colon)
to search for (space or more) we use expression
(\s+)
\s means space
+ means one or more
to search for(Alphanumeric word) we use expression
(\w+)
\w means Alphanumeric character
+ means one or more
to search for (Possible space or more) we use expression
(\s*)
\s means space
* means zero or more
so the regular expression would be int(\s+\w+\s*); it will return all uninitialized ints.
It would be great if we collect those regular expressions and keep them in a library to be our arsenal towards bad code.
do u have more regular expressions to share?
Subscribe to:
Post Comments (Atom)
4 comments:
actually this was very helpful some time ago.
I use this
and my current petite arsenal
=(\s+\n) (No line breaks after operator)
(\w+)(\s+\s)(\w+) (No 2 spaces between words)
(\s+); (No Spaces before semicolon)
Speaking of bullet-proofing code, I recommend this article: http://www.joelonsoftware.com/articles/Wrong.html . A very interesting read.
I tried the plugin you use (RegEx tester for eclipse) and it's really great.
Post a Comment