Retrieving String after given Regular expression
This Example describes the way to retrieve the String after giving expression.For this we are going to make program named Lookbehind.java. The steps involved in program Lookbehind.java are described below:-:-String regex = "(?<=http://www.)\\S+":-Here we have given the expression in the String form.Let us describe each expression seprately:-
?:-This character is used to match either one orzero times.
<=:- By this we mean String after "http://www.".
\\S:-Escaped backslash for re.compile.
Overall meaning of this expression is to print rest of the string after the string "http://www.".
Pattern p = Pattern.compile(regex):-Creating a pattern object and compiles the given regular expression into a pattern.
Matcher m = p.matcher(url):-Creates a matcher for matching the given input against pattern p.
Lookbehind.java
import java.util.regex.Matcher;
|
Output of the program
The url of the roseindia is http://www.roseindia.net.Rohini Name of the company is : roseindia.net. |
Download Source code