Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

 

and many more ....

 

 

Matcher start example

In this example we shall show you how to use Matcher.start() API method to get the start index of the previous match of a sequence against a pattern. To use Matcher.start() one should perform the following steps: Compile a String regular expression to a Pattern, using compile(String regex) API method of Pattern. Use an initial String to be matched against ...

Read More »

Matcher find demonstration

With this example we are going to demonstrate how to use Matcher.find() API method to find subsequences of an input sequence that matches a specified pattern. In short, a Matcher example is described below: A Matcher is created, using compile(String regex) API method of Pattern, that compiles a given regular expression to a Pattern. The Pattern is then used to ...

Read More »

Matcher reset example

This is an example of how to use Matcher.reset() API method to reset a Matcher, by discarding all of its explicit state information and setting its append position to zero. The matcher’s region is set to the default region, which is its entire character sequence. Resetting a matcher implies that you should: Compile a String regular expression to a Pattern, ...

Read More »

Back references example

In this example we shall show you how to use Matcher.replaceAll(String replacement) API method to replace every subsequence of an input sequence that matches a specified pattern with a given replacement string. To replace any subsequence of a given sequence with a given String one should perform the following steps: Compile a String regular expression to a Pattern, using compile(String ...

Read More »

Matcher.appendReplacement example

With this example we are going to demonstrate how to use Matcher.appendReplacement(StringBuffer sb, String replacement) API method to append to a StringBuffer the result of a Matcher. In short, to use a StringBuffer to append a Matcher’s result you should: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. Use matcher(CharSequence input) API ...

Read More »

Matcher groupCount example

In this example we shall show you how to use Matcher.groupCount() API method to get the number of capturing groups in a Matcher‘s pattern. To get the number of capturing groups in a matcher’s pattern one should perform the following steps: Compile a String regular expression to a Pattern, using compile(String regex) API method of Pattern. Use matcher(CharSequence input) API ...

Read More »

Matcher group example

This is an example of how to use Matcher.group(int group) API method to get the input subsequence captured by the given group during the previous match operation. Grouping with a Matcher implies that you should: Compile a String regular expression to a Pattern, using compile(String regex) API method of Pattern. Use matcher(CharSequence input) API method of Pattern to create a ...

Read More »

Match address using regular expressions

This is an example of how to match an address using regular expressions. We have created a method boolean isValidAddr(String addr) and used it to match some addresses to a specified pattern. The method is described below: The method reads a String address and returns true if a specified pattern matches the address and false otherwise. It has a a ...

Read More »

Regular expressions for IP v4 and IP v6 addresses

In this example we shall show you how to check if an address is an IPv4 or IPv6 address, using regular expressions. To check an address with regular expressions we have created three different patterns, as described in the steps below: The first pattern is creating by compiling a String regular expression that describes the IPv4 address, using compile(String regex) ...

Read More »

Swing GUI application for regular expression testing

This is an example of how to create a Swing GUI application for regular expression testing. The application creates a window that reads a pattern and a String and checks if the String matches the pattern and how many times the pattern appears in the String. The steps to create such an application are described below: Class GuiDemo extends the ...

Read More »