Sitemap
Surajkh

Surajkh

Passionate Software Developer

Regex(Regular Expressions) in Java

2 min readJul 22, 2023

Regular Expressions or Regex in Java is basically considered as an API for definition of different string patterns in order to perform various string manipulations operations over here.

Regex in Java considers different classes like Pattern Class,Matcher Class.

Lets go through each of the above defined classes:

Pattern Class:Pattern Class is basically used to create a pattern , which can be considered as a reference for string matching, let us go through the below code snippet.

Press enter or click to view image in full size
Pattern Class

As shown in the above code snippet we have created a pattern by making use of Pattern Class over here.

Get Surajkh’s stories in your inbox

Join Medium for free to get updates from this writer.

Matcher Class: is being used to match a String for the relevant Pattern being defined by the Pattern Class.

Let us go through the below code snippet :

Press enter or click to view image in full size
Matcher Class

Now we can consider the boolean result that is being fetched after performing the matching of the string to the defined string pattern using the matches() method.

Press enter or click to view image in full size
boolean result obtained after string pattern comparision.

Thank You.

--

--

Surajkh
Surajkh

Written by Surajkh

0 followers

Passionate Software Developer