Pattern matching using java.util.regex
java.util.regex library is available since Java 1.4. It can be used for matching character sequences against pattern specified by regular expression. It has two main classes Pattern and Matcher . An instance of the Pattern class represents a regular expression that is specified in string form in a syntax. Instances of the Matcher class are used to match character sequences against a given pattern. Input is provided to matchers via the CharSequence interface in order to support matching against characters from a wide variety of input sources. Here is the simple example, If you have to extract part of string based on the fixed pattern defined. For example the simple greeting string “Hello Yogesh, Welcome to Hyderabad.” In this sentence, we have to extract two info like name and location ( Yogesh & Hyderabad). First of all we need to define pattern to extract the same information. Java support regular expression for pattern matching, go through Java Pattern documentation to ...