-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegularExp.java
More file actions
30 lines (25 loc) · 1.09 KB
/
Copy pathRegularExp.java
File metadata and controls
30 lines (25 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// A regular expressioon is a sequenc of characters that froms a search pattern
// import from java.util.regex
/*
The package includes the following classes:
Pattern Class - Defines a pattern (to be used in a search)
Matcher Class - Used to search for the pattern
PatternSyntaxException Class - Indicates syntax error in a regular expression pattern
pattern.compile method is used to create the pattern
The matcher() method is used to search for the pattern in a string. It returns a Matcher object which contains information about the search that was performed.
The find() method returns true if the pattern was found in the string and false if it was not found.
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegularExp {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("w3schools", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher("Visit W3Schools!");
boolean matchFound = matcher.find();
if(matchFound) {
System.out.println("Match found");
} else {
System.out.println("Match not found");
}
}
}