Example usage for java.lang String matches

List of usage examples for java.lang String matches

Introduction

In this page you can find the example usage for java.lang String matches.

Prototype

public boolean matches(String regex) 

Source Link

Document

Tells whether or not this string matches the given regular expression.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    String addr = "my Address 12345";
    String namePattern = "([A-Za-z])+ (([A-Za-z])+\\.? )?([A-Za-z])+\\s*";

    String zipCodePattern = "\\d{5}(-\\d{4})?";
    String addressPattern = "^" + namePattern + "\\w+ .*, \\w+ " + zipCodePattern + "$";

    System.out.println(addr.matches(addressPattern));

}

From source file:com.luna.common.spring.SpeedUpSpringProcessor.java

public static void main(String[] args) {
    String c = "com.luna.sys.user.web.bind.A";
    System.out.println(c.matches("com\\.sishuok\\.es\\.sys.*\\.web\\.controller.*"));
}

From source file:com.daphne.es.common.spring.SpeedUpSpringProcessor.java

public static void main(String[] args) {
    String c = "com.daphne.es.sys.user.web.bind.A";
    System.out.println(c.matches("com\\.sishuok\\.es\\.sys.*\\.web\\.controller.*"));
}

From source file:cn.guoyukun.spring.SpeedUpSpringProcessor.java

public static void main(String[] args) {
    String c = "com.sishuok.es.sys.user.web.bind.A";
    System.out.println(c.matches("com\\.sishuok\\.es\\.sys.*\\.web\\.controller.*"));
}

From source file:com.cloudy.common.spring.SpeedUpSpringProcessor.java

public static void main(String[] args) {
    String c = "com.gzl.portal.sys.user.web.bind.A";
    System.out.println(c.matches("com\\.sishuok\\.es\\.sys.*\\.web\\.controller.*"));
}

From source file:examples.mail.IMAPImportMbox.java

public static void main(String[] args) throws IOException {
    if (args.length < 2) {
        System.err.println(/*from w  w  w . j a v  a 2 s.co  m*/
                "Usage: IMAPImportMbox imap[s]://user:password@host[:port]/folder/path <mboxfile> [selectors]");
        System.err.println("\tWhere: a selector is a list of numbers/number ranges - 1,2,3-10"
                + " - or a list of strings to match in the initial From line");
        System.exit(1);
    }

    final URI uri = URI.create(args[0]);
    final String file = args[1];

    final File mbox = new File(file);
    if (!mbox.isFile() || !mbox.canRead()) {
        throw new IOException("Cannot read mailbox file: " + mbox);
    }

    String path = uri.getPath();
    if (path == null || path.length() < 1) {
        throw new IllegalArgumentException("Invalid folderPath: '" + path + "'");
    }
    String folder = path.substring(1); // skip the leading /

    List<String> contains = new ArrayList<String>(); // list of strings to find
    BitSet msgNums = new BitSet(); // list of message numbers

    for (int i = 2; i < args.length; i++) {
        String arg = args[i];
        if (arg.matches("\\d+(-\\d+)?(,\\d+(-\\d+)?)*")) { // number,m-n
            for (String entry : arg.split(",")) {
                String[] parts = entry.split("-");
                if (parts.length == 2) { // m-n
                    int low = Integer.parseInt(parts[0]);
                    int high = Integer.parseInt(parts[1]);
                    for (int j = low; j <= high; j++) {
                        msgNums.set(j);
                    }
                } else {
                    msgNums.set(Integer.parseInt(entry));
                }
            }
        } else {
            contains.add(arg); // not a number/number range
        }
    }
    //        System.out.println(msgNums.toString());
    //        System.out.println(java.util.Arrays.toString(contains.toArray()));

    // Connect and login
    final IMAPClient imap = IMAPUtils.imapLogin(uri, 10000, null);

    int total = 0;
    int loaded = 0;
    try {
        imap.setSoTimeout(6000);

        final BufferedReader br = new BufferedReader(new FileReader(file)); // TODO charset?

        String line;
        StringBuilder sb = new StringBuilder();
        boolean wanted = false; // Skip any leading rubbish
        while ((line = br.readLine()) != null) {
            if (line.startsWith("From ")) { // start of message; i.e. end of previous (if any)
                if (process(sb, imap, folder, total)) { // process previous message (if any)
                    loaded++;
                }
                sb.setLength(0);
                total++;
                wanted = wanted(total, line, msgNums, contains);
            } else if (startsWith(line, PATFROM)) { // Unescape ">+From " in body text
                line = line.substring(1);
            }
            // TODO process first Received: line to determine arrival date?
            if (wanted) {
                sb.append(line);
                sb.append(CRLF);
            }
        }
        br.close();
        if (wanted && process(sb, imap, folder, total)) { // last message (if any)
            loaded++;
        }
    } catch (IOException e) {
        System.out.println(imap.getReplyString());
        e.printStackTrace();
        System.exit(10);
        return;
    } finally {
        imap.logout();
        imap.disconnect();
    }
    System.out.println("Processed " + total + " messages, loaded " + loaded);
}

From source file:com.thinker.arch.common.spring.SpeedUpSpringProcessor.java

public static void main(String[] args) {
    String c = "com.thinker.arch.platform.sys.user.web.bind.A";
    System.out.println(c.matches("com\\.sishuok\\.es\\.sys.*\\.web\\.controller.*"));
}

From source file:Main.java

public static void main(String args[]) {
    String addr = "street 124 a0a";
    String nameToken = "\\p{Upper}(\\p{Lower}+\\s?)";
    String namePattern = "(" + nameToken + "){2,3}";
    String zipCodePattern = "\\d{5}(-\\d{4})?";
    String addressPattern = "^" + namePattern + "\\w+ .*, \\w+ " + zipCodePattern + "$";
    System.out.println(addr.matches(addressPattern));

}

From source file:markov.java

/**
 * @param args/*from  www.  j  av  a  2 s. c om*/
 */
public static void main(String[] args) {

    // hack: eclipse don't support IO redirection worth a shit
    // try {
    // System.setIn(new FileInputStream("./json"));
    // } catch (FileNotFoundException e1) {
    // // TODO Auto-generated catch block
    // e1.printStackTrace();
    // }

    boolean graphMode = false;
    boolean jsonMode = false;
    boolean jsonRecoverMode = false;
    boolean endNode = false;

    int count = -1;

    long n = 0;
    long sumOfSqr = 0;
    long sum = 0;

    for (String s : args) {

        if (!s.matches("^-[vegjJh]*(c[0-9]*)?$")) {
            System.out.println("invalid argument");
            return;
        }

        if (s.matches("^-.*h.*")) {
            System.out.println(HELP);
            return;
        }
        if (s.matches("^-.*v.*")) {
            verbose = true;
            log("verbose mode");
        }
        if (s.matches("^-.*g.*")) {
            graphMode = true;
            log("graph mode");
        }
        if (s.matches("^-.*j.*")) {
            jsonMode = true;
            log("json mode");
        }
        if (s.matches("^-.*J.*")) {
            jsonRecoverMode = true;
            log("json recover mode");
        }
        if (s.matches("^-.*e.*")) {
            endNode = true;
            log("include end node");
        }
        if (s.matches("^-.*c[0-9]*$")) {
            log("counted output mode");
            count = Integer.parseInt(s.replaceAll("^-.*c", ""));
        }

        boolean error = (graphMode == true && jsonMode == true);
        if (!error) {
            error = (count > -1) && (graphMode == true || jsonMode == true);
        }

        if (error) {
            System.err.println("[error] switches j, g and, c are mutualy exclusive.");
            return;
        }

    }

    StateTransitionDiagram<Character> std;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    try {
        if (!jsonRecoverMode) {
            Trainer<Character> trainer = new Trainer<Character>();
            String s = br.readLine();
            while (s != null) {
                trainer.train(string2List(s));
                n++;
                sumOfSqr += s.length() * s.length();
                sum += s.length();
                s = br.readLine();
            }
            if (n == 0) {
                System.err
                        .println("Invalid corpus: At least one sample is required, two to make it interesting");
                return;
            }
            std = trainer.getTransitionDiagram();
        } else {
            std = new StateTransitionDiagram<Character>();
            GsonStub gstub = new Gson().fromJson(br, GsonStub.class);
            n = gstub.meta.n;
            sum = gstub.meta.sum;
            sumOfSqr = gstub.meta.sumOfSqr;

            for (Entry<String, StateStub> entry : gstub.states.entrySet()) {
                State<Character> state;
                if (entry.getKey().equals("null")) {
                    state = std.getGuard();
                } else {
                    state = std.getState(Character.valueOf(entry.getKey().charAt(0)));
                }
                for (Entry<String, Integer> transitions : entry.getValue().transitions.entrySet()) {
                    State<Character> tranny;
                    if (transitions.getKey().equals("null")) {
                        tranny = std.getGuard();
                    } else {
                        tranny = std.getState(Character.valueOf(transitions.getKey().charAt(0)));
                    }

                    state.addTransition(tranny.getValue(), transitions.getValue());
                }
            }
        }
        if (graphMode) {
            if (endNode) {
                System.out.println(std.toString());
            } else {
                System.out.println(std.removeEndGuards().toString());
            }
            return;
        }
        if (jsonMode) {
            Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

            String partialJson;
            if (endNode) {
                partialJson = gson.toJson(std);
            } else {
                partialJson = gson.toJson(std.removeEndGuards());
            }
            GsonStub gstub = new Gson().fromJson(partialJson, GsonStub.class);
            gstub.meta = new Meta();
            gstub.meta.n = n;
            gstub.meta.sum = sum;
            gstub.meta.sumOfSqr = sumOfSqr;

            System.out.println(gson.toJson(gstub));
            return;
        }

        Generator<Character> generator;
        if (endNode) {
            generator = new EndTagGenerator<Character>(std);
        } else {
            double sd = ((double) sumOfSqr - (double) (sum * sum) / (double) n) / (double) (n - 1);
            double mean = (double) sum / (double) n;
            log(String.format("mean: %.4f sd: %.4f", mean, sd));
            NormalDistributionImpl dist = new NormalDistributionImpl(mean, sd);
            generator = new NormalizedGenerator<Character>(std.removeEndGuards(), dist);
        }
        if (count >= 0) {
            for (int c = 0; c < count; c++) {
                output(generator);
            }
        } else {
            while (true) {
                output(generator);
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:cz.cuni.mff.ufal.dspace.app.MoveItems.java

/**
 * main method to run the MoveItems action
 * //from  w w w. j  av  a 2 s  .c  o  m
 * @param argv
 *            the command line arguments given
 * @throws SQLException
 */
public static void main(String[] argv) throws SQLException {
    // Create an options object and populate it
    CommandLineParser parser = new PosixParser();

    Options options = new Options();

    options.addOption("l", "list", false, "list collections");
    options.addOption("s", "source", true, "source collection ID");
    options.addOption("t", "target", true, "target collection ID");
    options.addOption("i", "inherit", false, "inherit target collection privileges (default false)");
    options.addOption("h", "help", false, "help");

    // Parse the command line arguments
    CommandLine line;
    try {
        line = parser.parse(options, argv);
    } catch (ParseException pe) {
        System.err.println("Error parsing command line arguments: " + pe.getMessage());
        System.exit(1);
        return;
    }

    if (line.hasOption('h') || line.getOptions().length == 0) {
        printHelp(options, 0);
    }

    // Create a context
    Context context;
    try {
        context = new Context();
        context.turnOffAuthorisationSystem();
    } catch (Exception e) {
        System.err.println("Unable to create a new DSpace Context: " + e.getMessage());
        System.exit(1);
        return;
    }

    if (line.hasOption('l')) {
        listCollections(context);
        System.exit(0);
    }

    // Check a filename is given
    if (!line.hasOption('s')) {
        System.err.println("Required parameter -s missing!");
        printHelp(options, 1);
    }

    Boolean inherit;

    // Check a filename is given
    if (line.hasOption('i')) {
        inherit = true;
    } else {
        inherit = false;
    }

    String sourceCollectionIdParam = line.getOptionValue('s');
    Integer sourceCollectionId = null;

    if (sourceCollectionIdParam.matches("\\d+")) {
        sourceCollectionId = Integer.valueOf(sourceCollectionIdParam);
    } else {
        System.err.println("Invalid argument for parameter -s: " + sourceCollectionIdParam);
        printHelp(options, 1);
    }

    // Check source collection ID is given
    if (!line.hasOption('t')) {
        System.err.println("Required parameter -t missing!");
        printHelp(options, 1);
    }
    String targetCollectionIdParam = line.getOptionValue('t');
    Integer targetCollectionId = null;

    if (targetCollectionIdParam.matches("\\d+")) {
        targetCollectionId = Integer.valueOf(targetCollectionIdParam);
    } else {
        System.err.println("Invalid argument for parameter -t: " + targetCollectionIdParam);
        printHelp(options, 1);
    }

    // Check target collection ID is given
    if (targetCollectionIdParam.equals(sourceCollectionIdParam)) {
        System.err.println("Source collection id and target collection id must differ");
        printHelp(options, 1);
    }

    try {

        moveItems(context, sourceCollectionId, targetCollectionId, inherit);

        // Finish off and tidy up
        context.restoreAuthSystemState();
        context.complete();
    } catch (Exception e) {
        context.abort();
        System.err.println("Error committing changes to database: " + e.getMessage());
        System.err.println("Aborting most recent changes.");
        System.exit(1);
    }
}