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:Main.java

public static void main(String[] argv) throws Exception {

    boolean retval = false;
    String date = "12/12/1212";
    String datePattern = "\\d{1,2}-\\d{1,2}-\\d{4}";
    retval = date.matches(datePattern);

}

From source file:MainClass.java

public static void main(String args[]) {

    String date = "12-12-1212";

    String datePattern = "\\d{1,2}-\\d{1,2}-\\d{4}";
    System.out.println(date.matches(datePattern));

}

From source file:Main.java

public static void main(String args[]) {
    String phone = "(111)-111-1111";
    String phoneNumberPattern = "(\\d-)?(\\d{3}-)?\\d{3}-\\d{4}";
    System.out.println(phone.matches(phoneNumberPattern));
}

From source file:MainClass.java

public static void main(String args[]) {
    String phone = "123-(456)-9999";

    String phoneNumberPattern = "(\\d-)?(\\d{3}-)?\\d{3}-\\d{4}";

    System.out.println(phone.matches(phoneNumberPattern));

}

From source file:Main.java

public static void main(String args[]) {
    boolean retval = false;

    String name = "first last";
    String nameToken = "\\p{Upper}(\\p{Lower}+\\s?)";

    String namePattern = "(" + nameToken + "){2,3}";

    retval = name.matches(namePattern);

}

From source file:MainClass.java

public static void main(String args[]) {

    String name = "First Name";

    String nameToken = "\\p{Upper}(\\p{Lower}+\\s?)";
    String namePattern = "(" + nameToken + "){2,3}";

    System.out.println(name.matches(namePattern));

}

From source file:di.uniba.it.tee2.wiki.Wikidump2Text.java

/**
 * @param args the command line arguments
 *//*  ww w.j a v a 2 s .  c o m*/
public static void main(String[] args) {
    try {
        CommandLine cmd = cmdParser.parse(options, args);
        if (cmd.hasOption("l") && cmd.hasOption("d") && cmd.hasOption("o")) {
            encoding = cmd.getOptionValue("e", "UTF-8");
            int counter = 0;
            try {
                BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                        new GZIPOutputStream(new FileOutputStream(cmd.getOptionValue("o"))), "UTF-8"));
                WikipediaDumpIterator it = new WikipediaDumpIterator(new File(cmd.getOptionValue("d")),
                        encoding);
                PageCleaner cleaner = PageCleanerWrapper.getInstance(cmd.getOptionValue("l"));
                while (it.hasNext()) {
                    WikiPage wikiPage = it.next();
                    ParsedPage parsedPage = wikiPage.getParsedPage();
                    if (parsedPage != null) {
                        String title = wikiPage.getTitle();
                        if (!title.matches(notValidTitle)) {
                            if (parsedPage.getText() != null) {
                                writer.append(cleaner.clean(parsedPage.getText()));
                                writer.newLine();
                                writer.newLine();
                                counter++;
                                if (counter % 10000 == 0) {
                                    System.out.println(counter);
                                    writer.flush();
                                }
                            }
                        }
                    }
                }
                writer.flush();
                writer.close();
            } catch (Exception ex) {
                Logger.getLogger(Wikidump2Text.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.out.println("Indexed pages: " + counter);
        } else {
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("Wikipedia dump to text", options, true);
        }
    } catch (ParseException ex) {
        Logger.getLogger(Wikidump2Text.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.github.liyp.test.TestMain.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // add a shutdown hook to stop the server
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override/*from  w  w w .  j  a  v a 2  s.  c o m*/
        public void run() {
            System.out.println("########### shoutdown begin....");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("########### shoutdown end....");
        }
    }));

    System.out.println(args.length);
    Iterator<String> iterator1 = IteratorUtils
            .arrayIterator(new String[] { "one", "two", "three", "11", "22", "AB" });
    Iterator<String> iterator2 = IteratorUtils.arrayIterator(new String[] { "a", "b", "c", "33", "ab", "aB" });

    Iterator<String> chainedIter = IteratorUtils.chainedIterator(iterator1, iterator2);

    System.out.println("==================");

    Iterator<String> iter = IteratorUtils.filteredIterator(chainedIter, new Predicate() {
        @Override
        public boolean evaluate(Object arg0) {
            System.out.println("xx:" + arg0.toString());
            String str = (String) arg0;
            return str.matches("([a-z]|[A-Z]){2}");
        }
    });
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }

    System.out.println("===================");

    System.out.println("asas".matches("[a-z]{4}"));

    System.out.println("Y".equals(null));

    System.out.println(String.format("%02d", 1000L));

    System.out.println(ArrayUtils.toString(splitAndTrim(" 11, 21,12 ,", ",")));

    System.out.println(new ArrayList<String>().toString());

    JSONObject json = new JSONObject("{\"keynull\":null}");
    json.put("bool", false);
    json.put("keya", "as");
    json.put("key2", 2212222222222222222L);
    System.out.println(json);
    System.out.println(json.get("keynull").equals(null));

    String a = String.format("{\"id\":%d,\"method\":\"testCrossSync\"," + "\"circle\":%d},\"isEnd\":true", 1,
            1);
    System.out.println(a.getBytes().length);

    System.out.println(new String[] { "a", "b" });

    System.out.println(new JSONArray("[\"aa\",\"\"]"));

    String data = String.format("%9d %s", 1, RandomStringUtils.randomAlphanumeric(10));
    System.out.println(data.getBytes().length);

    System.out.println(ArrayUtils.toString("1|2| 3|  333||| 3".split("\\|")));

    JSONObject j1 = new JSONObject("{\"a\":\"11111\"}");
    JSONObject j2 = new JSONObject(j1.toString());
    j2.put("b", "22222");
    System.out.println(j1 + " | " + j2);

    System.out.println("======================");

    String regex = "\\d+(\\-\\d+){2} \\d+(:\\d+){2}";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher("2015-12-28 15:46:14  _NC250_MD:motion de\n");
    String eventDate = matcher.find() ? matcher.group() : "";

    System.out.println(eventDate);
}

From source file:TestDumpRecord.java

public static void main(String[] args) throws NITFException {
    List<String> argList = Arrays.asList(args);
    List<File> files = new LinkedList<File>();
    for (String arg : argList) {
        File f = new File(arg);
        if (f.isDirectory()) {
            File[] dirFiles = f.listFiles(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    String ext = FilenameUtils.getExtension(name).toLowerCase();
                    return ext.matches("nitf|nsf|ntf");
                }//from   w w  w  .  j a v  a 2 s  .co m
            });
            files.addAll(Arrays.asList(dirFiles));
        } else
            files.add(f);
    }

    Reader reader = new Reader();
    for (File file : files) {
        PrintStream out = System.out;

        out.println("=== " + file.getAbsolutePath() + " ===");
        IOHandle handle = new IOHandle(file.getAbsolutePath());
        Record record = reader.read(handle);
        dumpRecord(record, reader, out);
        handle.close();

        record.destruct(); // tells the memory manager to decrement the ref
        // count
    }
}

From source file:de.tor.tribes.util.parser.TroopsParser.java

public static void main(String[] args) {

    /*/*  w w  w. j  av a 2  s . c o m*/
     * Transferable t = (Transferable) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); try { String s = " 003 |
     * Spitfire (471|482) K44\n" + "eigene    2500    1500    0    1964    500    0    0    1396    0    0    0    0    Befehle\n" + "im Dorf    2500    1500    0    1964    500    0    0    1396    0    0
     * 0    0    Truppen\n" + "auswrts    0    0    0    0    0    0    0    0    0    0    0    0\n" + "unterwegs    0    0    0    0    0    0    0    0    0    0    0    0    Befehle\n" + "2Fast4You (475|480)
     * K44\n" + "eigene    600    500    0    0    134    0    0    354    0    0    0    1    Befehle\n" + "im Dorf    600    500    0    0    134    0    0    354    0    0    0    1    Truppen\n" + "auswrts
     * 4400    3000    0    3000    66    0    0    1046    0    0    0    0\n" + "unterwegs    0    0    0    0    0    0    0    0    0    0    0    0    Befehle\n";
     *
     *
     * String data = (String) t.getTransferData(DataFlavor.stringFlavor); TroopsParser.parse(data); } catch (Exception e) {
     * e.printStackTrace();
    }
     */

    String token = "(120|192)";
    System.out.println(token.matches("\\(*[0-9]{1,3}\\|[0-9]{1,3}\\)*"));
    token = "(12:23:12)";
    System.out.println(token.matches("\\(*[0-9]{1,2}\\:[0-9]{1,2}\\:[0-9]{1,2}\\)*"));

    // TroopsParser.parse(pTroopsString);
}