-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregexsample.java
More file actions
31 lines (22 loc) · 935 Bytes
/
regexsample.java
File metadata and controls
31 lines (22 loc) · 935 Bytes
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
31
Picture of Small Java program using regular expressions
// This program will test regular expresssions
// on a file that the user inputs at the program's request.
// Distributed under the GNU GPL: www.gnu.org
import java.io.*;
import java.util.regex.*;
public class regex1 {
public static void main(String args[]) throws IOException {
String userEntry;
// Ask user to enter data into program that will be matched
// against the regex
InputStreamReader delta = new InputStreamReader(System.in);
BufferedReader echo = new BufferedReader(delta);
System.out.println("Enter data to be matched against regex.");
userEntry = echo.readLine();
String golf = new String("Linux|FreeBSD|linux|freebsd");
Pattern alpha = Pattern.compile(golf);
Matcher bravo = alpha.matcher(userEntry);
boolean charlie = bravo.matches();
System.out.println("Is it a match? " + charlie);
} // end main method
} // end class regex1