This Example describes the way to retrieve the String using regular expression. For this we are going to make program named Pattern_Resetting.java. The steps involved in program Pattern_Resetting.java are described below:-
String regex = "[frb][aiu]":-Defining regression in string form, Here " " determines text and finds parts that match the provided specification.
Pattern pattern = Pattern.compile(regex):-Creating a pattern object and compiling the given regular expression into a given pattern.
String text = "fix the rug ":-Declaring text from where match will be provided.
Matcher matcher = pattern.matcher(text):- Creates a matcher for matching the given input against pattern.
(matcher.find()):- This is the method of matcher class which is used for finding the next subsequence of the input sequence and it usually returns a boolean value.
Output of the program:-
|fi ru fi ri|
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial
Ask Questions? Discuss: Pattern resetting using regular expression
Post your Comment