This Example describes the way to retrieve the String using expression.For this we are going to make program named NotLookahead.java. The steps involved in program NotLookahead.java are described below:-
String regex = "Tim (?!Bueneman)[A-Z]\\w+":-Here we have given the expression in the String form.The meaning of the whole expression is to find the name followed by Tim,Let us describe each expression seprately:-
?:-This character is used to match either one or zero times.
\\w:-This character is used to match any alphanumeric character
Pattern p = Pattern.compile(regex):-Creating a pattern object and compiles the given regular expression into a pattern.
Matcher m = p.matcher(no):-Creates a matcher for matching the given input against pattern p.
NotLookahead.java:-
import java.util.regex.Matcher;
|
Output of the program:-
|
Name starting with Tim from the text are: Tim Right Tim Singh Tim Khan Tim Yadav Tim Sharma |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Retrieve the String using expression
Post your Comment