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|
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: August 30, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles