Overview
Regular expressions allow you to find patterns in strings and work with them. They are an invaluable tool and allow a simpler and faster implementation for many non-trivial tasks on strings.
When to use regular expressions?
Use regular expressions when..
- you want to parse a string
- you want to replace patterns in a string
Do not use regular expressions when..
- your input is very complex. For example, don't try to parse a string containing XML or HTML with regular expressions (you will almost always fail to consider all cases), but use an appropriate library instead.
- you need to squeeze the last bit of performance out of your code and you are willing to put a lot of effort into this (simple implementations will usually not beat a pre-compiled regular expression)
Java supports regular expressions since version 1.4.
This tutorial uses the assert statement to explain the topic. If you don't fully understand assert yet, read Java Basics: Assert first.

