Home » Core Java » util » regex » Page 4

regex

Line ending matching example

With this example we are going to demonstrate how to check a line ending matching. We are using Patterns and Matchers against each pattern. In short, to check a line ending matching you should: Create a String array that contains the patterns to be used. For every pattern in the array compile it to a Pattern, using compile(string regex) API ...

Read More »

Matcher group example – Part 2

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 »

Matcher replaceAll – Part 2

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 group with parameter example

With this example we are going to demonstrate how to use Matcher.group(int group) API method to get the input subsequence captured by the given group during the previous match operation. In short, to use group(int group) API method of Matcher you should: Compile a String regular expression to a Pattern, using compile(String regex) API method of Pattern. Use matcher(CharSequence input) ...

Read More »

Matcher replaceFirst example

This is an example of how to use Matcher.replaceFirst(String replacement) API method to replace the first subsequence of an input sequence that matches a specified pattern with a given replacement string. Replacing the first subsequence of a String input with a given string using a Matcher implies that you should: Compile a String regular expression to a Pattern, using compile(String ...

Read More »

Matcher replaceAll 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 lookingAt example

With this example we are going to demonstrate how to use Matcher.lookingAt() API method to match an input sequence, starting at the beginning of the input, against a specified pattern. In short, to match a Sting input against a pattern with Matcher.lookingAt() API method you should: Compile a String regular expression to a Pattern, using compile(String regex) API method of ...

Read More »

Matcher match example

This is an example of how to make a match using a Matcher against a Pattern. Making a match using a Matcher against 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 given String ...

Read More »

Matcher end with parameter example

In this example we shall show you how to use Matcher.end(int group) API method to get the offset after the last character of the subsequence captured by the given group, during the previous match operation. To use Matcher.end(int group) one should perform the following steps: Compile a String regular expression to a Pattern, using compile(String regex) API method of Pattern. Use an ...

Read More »

Matcher end example

With this example we are going to demonstrate how to use Matcher.end() API method to get the offset after the last character matched against a pattern. In short, to use Matcher.end() API method you should: Compile a String regular expression to a Pattern, using compile(String regex) API method of Pattern. Use an initial String to be matched against the Pattern. Use ...

Read More »