Home » Core Java » util » regex » Page 6

regex

Swing GUI application for regular expression testing

Bipartite Graph

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 »

Pattern matcher example – Part 2

Bipartite Graph

This is an example of how to use a Pattern Matcher to match an input String with a specified pattern. Matching a String to a pattern 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 Matcher that will ...

Read More »

Pattern matcher example

Bipartite Graph

In this example we shall show you how to use a Matcher and a Pattern in Java to match an input String to a specified pattern. To use a matcher and a 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 method of ...

Read More »

Regular expression match group example

Bipartite Graph

This is an example of how to use a regular expression match group. Using a regular expression to group matches of a String with a pattern 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 Matcher that will match the given ...

Read More »

Split a string into an array by regular expressions

Bipartite Graph

This is an example of how to split a string into an array by regular expressions. Splitting a string by regular expressions implies that you should: Compile a String regular expression to a Pattern, using compile(String regex) API method of Pattern. Split the given input sequence around matches of this pattern, using split(CharSequence input) API method of Pattern. The result of ...

Read More »

Case control example

Bipartite Graph

In this example we shall show you how to handle a case control using a class with a regular expression. To use a regular expression to check on a case one should perform the following steps: Compile a String regular expression to a Pattern, using compile(String regex, int flags) API method of Pattern, with case-insensitive matching. Compile the same regular expression ...

Read More »

String.matches method example

Bipartite Graph

With this example we shall show you how to use String.matches(String regex) API method to check if a given String matches a given regular expression. Checking if a String matches a regular expression implies that you should: Create a new String pattern, that is a regular expression. Use matches(String regex) API method of String to check if the String matches ...

Read More »

List files with regular expression filtering

Bipartite Graph

This is an example of how to list files using regular expression filtering. In order to list Files using regular expressions to filter them we have set the example below: Class DirFilter implements the FilenameFilter. It has a Pattern that is initialized by compiling a String regular expression to a Pattern, using compile(String regex) API method of Pattern. It also has a ...

Read More »

Remove line termination characters from string

Bipartite Graph

In this example we shall show you how to remove line termination characters from a String, using regular expressions. To remove line termination characters from a String one should perform the following steps: Create a String that contains a line separator as specified by the System.getProperty(String key) API method. Compile a String regular expression to a Pattern, using compile(String regex) ...

Read More »

Compile Reg Ex pattern with multiple flags

Bipartite Graph

With this example we shall show you how to compile regular expression to a Pattern with multiple flags. Compiling a regular expression to a Pattern with multiple flags 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 Matcher that will match ...

Read More »