Also, heres a little tidbit that makes practicing or refining regular expressions very easy using perls command line options.
From your command line type:
# perl -ne 'print if /foo/'
Then you can see if the regex works the way you expect by typing in possible matches and it will echo it back to you. If it doesnt match it wont echo it. Then just ctrl-c out of it and modify the regex as necessary.
For refining my substitutions I use:
# perl -pi -e 's/foo/oof/'
Never forget the power of using perl as a command line tool as well as a programming language! I am amazed at its flexibility all the damn time. For example if you need to do the same substition on a few hundred files under a directory you can try something like this:
# perl -pi -e 's/foo/oof/g' *.txt
Kick ass! Run 'perldoc perlrun' for even more possibilities.
If someone had shown me those tricks when I was struggling with regexes it would have made my life much much easier.
__________________
Remember, wherever you go... there you are.
|