Java - Regular Expressions

What is Regular Expression?

Developers often encounter a requirement where we need to check if the contents of a string follow a particular pattern. For example, we might want to know if the string contains any white space, or any non alphanumeric characters, or if it starts with a capital, ... There are several such scenarios. Few decades ago, people had to get down to using a substring (or some pointer arithmetic in the age of C). But as this requirement surfaced again and again, developers came up with libraries that helped with this task, that formalized over time as regular expressions. In due time, Regular expressions became an integral part of any language.
Since JDK 1.4, Java introduced the package java.util.regex - that contains all the classes that aid regular expressions.
A Regular Expression is a way to define a string pattern. Regular expression is not limited to Java. Today, most languages have regular expressions built into them. The syntax of regular expressions is quite common among all these languages. There are some minor differences that each language proposes. But, once we have a good grasp on any one, it will not require much effort to use the same knowledge elsewhere.
Thus, there are two important components to understanding Java Regular Expressions


This is a top level introduction to the concepts of Java Reflection API. For more details, you can check out the Java Documentation. If you want a detailed analysis, you can check out this book