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?
Showing posts with label Regular Expressions. Show all posts
Showing posts with label Regular Expressions. Show all posts
Wednesday, May 23, 2007
Subscribe to:
Posts (Atom)