Regular expressions are a language of string patterns built in to most modern programming languages, including Java 1.4 onward; they can be used for: searching, extracting from, and modifying text.

How many times have you come to a piece of code, only to find a tangled mess of string comparisons and index checks - how many time have you written one? Granted, there is a time and place for index-based iteration and tokenization, but maybe it's time to bite the bullet and learn how to use a real text-manipulation tool.

Regular expressions are not difficult to master – in fact, they are quite easy. A good strategy, whenever building a new regular expression, is to start with the simplest, most general match possible. From there, add more and more complexity until you have matched, substituted, or inserted exactly what you need. It is an iterative development process, unless you are already very practiced, so just because it seems difficult at first, does not mean that you should give up and go back to your web of `indexOf` and `contains`.

Regular expressions can greatly reduce time to delivery, and can also greatly reduce code complexity; however, this comes at a cost. Regular expressions can become fragile, and without proper unit tests, maintainance can become expensive and dangerous. Like any other piece of code, tests are life; don't do unto others what you would not have them do unto you.

Don't leave complex regular expressions un-tested, and conversely, if you are confused by a regular epression you find, maybe you should spend a little time to figure out what it does, and write some tests to validate your beliefs - in the end, you'll be glad you did.

Take initiative.

To learn more about regular expressions in Java, check out this hands-on example based tutorial: and may the force be with you.