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.
Output of the program:-
Name starting with Tim from the text are: |
Recommend the tutorial