loading
// 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

About This Instructable

351views

5favorites

License:

More by matt392:How to Write a Simple Linux Shell Script Extending Lever on Spray Bottle Hand Saw From Wood Shims and Jig Saw Blade 
Add instructable to: