public void test_base5() throws PatternCompiler_E, IOException { // ^$ init("########\n abcd1234\nefgh1234\n########\n", "(^\\w+$)\\s+"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "efgh1234\n"); assertEquals(groups[0].length, 1); assertEquals(groups[1][0].toString(), "efgh1234"); init("########\n abcd1234\nefgh1234 ########\n", "(^\\w+)\\s+"); find(); groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "efgh1234 "); assertEquals(groups[0].length, 1); assertEquals(groups[1][0].toString(), "efgh1234"); init("########\n abcd1234\nefgh1234\n########\n", "^(\\w+$)\\s+"); find(); groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "efgh1234\n"); assertEquals(groups[0].length, 1); assertEquals(groups[1][0].toString(), "efgh1234"); }
public void test19() throws IOException { this.init("abcabcabcabc;", "(abc)+;"); this.find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "abcabcabcabc;"); assertEquals(groups[1].length, 4); for (int i = 0; i < 4; ++i) { assertEquals(groups[1][i].toString(), "abc"); } ////////////////////////////////////////////////////// this.init("abcabcabcabc", "(abc)+"); this.find(); groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "abcabcabcabc"); assertEquals(groups[1].length, 4); for (int i = 0; i < 4; ++i) { assertEquals(groups[1][i].toString(), "abc"); } ////////////////////////////////////////////////////// this.init("abcabc;", "(abc)+"); this.find(); groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "abcabc"); assertEquals(groups[1].length, 2); for (int i = 0; i < 2; ++i) { assertEquals(groups[1][i].toString(), "abc"); } }
public void test28() throws PatternCompiler_E, IOException { // ±ß½ç²âÊÔ.Æ¥Åä'\*+' init("*********1", "\\*+"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "*********"); }
public void test24() throws IOException { this.init("0", "\\d"); this.find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "0"); }
private int find() { int ret = -1; try { ret = matcher.find(); if (ret < 0) return ret; Submatched[][] groups = matcher.getMatched(); int index = 0; for (int i = 0; i < groups.length; ++i) { Submatched[] m = groups[i]; System.out.println( "[GROUP" + index + "]--------------------------------------------------"); ++index; for (int j = 0; j < m.length; ++j) { System.out.print('['); System.out.print(m[j].toString()); System.out.print(']'); } System.out.print("\n"); } } catch (EOFException ex) { System.out.println("not matched"); // this.assertTrue(false); } catch (IOException ex) { ex.printStackTrace(); this.assertTrue(false); } catch (InterruptedException ex) { ex.printStackTrace(); } return ret; }
public void test22() throws IOException { this.init("532154357756654", "\\d*577"); this.find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "5321543577"); }
public void test38() throws PatternCompiler_E, IOException { init("³É¹¦µÇ¼\n--- end", "³É¹¦µÇ¼\\s+--- end"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "³É¹¦µÇ¼\n--- end"); }
public void test39() throws PatternCompiler_E, IOException { init("name=John;height=173;weight=63;", "height=\\d+"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "height=173"); }
public void test40() throws PatternCompiler_E, IOException { init("A [email protected] login", "\\w+@[\\d+\\.]+"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "[email protected]"); }
public void test_base1() throws PatternCompiler_E, IOException { // ×Ö·û init("..1\n\rL \t?a\r", ".\\D\\d\\n\\r\\S\\s\\t\\W\\w\\x0D"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "..1\n\rL \t?a\r"); }
public void test30() throws PatternCompiler_E, IOException { init("1234", "abcd|1234"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "1234"); }
public void test_base3() throws PatternCompiler_E, IOException { // »ò init("ls\nuser home\nquit\nbye bye!\n", "exit|quit|stop"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "quit"); }
public void test51() throws PatternCompiler_E, IOException { init("app.log.20070709-1752353", "app\\.log\\.\\d+(?:-\\d+)?"); assertEquals(0, find()); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0].length, 1); assertEquals(groups[0][0].toString(), "app.log.20070709-1752353"); }
public void test_base4() throws PatternCompiler_E, IOException { // Á¿´Ê init("It's NO.3!", "NO.\\d?!"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "NO.3!"); init("It's NO.!It's NO.1!It's NO.123!\n", "(It's NO.\\d*!)+\n"); find(); groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "It's NO.!It's NO.1!It's NO.123!\n"); assertEquals(groups[1].length, 3); assertEquals(groups[1][0].toString(), "It's NO.!"); assertEquals(groups[1][1].toString(), "It's NO.1!"); assertEquals(groups[1][2].toString(), "It's NO.123!"); }
public void test41() throws PatternCompiler_E, IOException { init("* @author Hong", "(@\\w+)*"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "@author"); assertEquals(groups[1][0].toString(), "@author"); }
public void test37() throws PatternCompiler_E, IOException { init("abcdefg1234576_xyz.", "(\\w+)\\W"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "abcdefg1234576_xyz."); assertEquals(groups[1].length, 1); assertEquals(groups[1][0].toString(), "abcdefg1234576_xyz"); }
public void test32() throws PatternCompiler_E, IOException { init("abcd123;", "(\\d+|\\W+)"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "123"); assertEquals(groups[1].length, 1); assertEquals(groups[1][0].toString(), "123"); }
public void test45() throws PatternCompiler_E, IOException { String str = "+++ HW_SHLR 2004-07-05 13:17:11"; init(str, "(\\+{3})\\s+\\S+\\s+\\d{4}-\\d{2}-\\d{2}\\s+(\\d{2}:\\d{2}:\\d{2})"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 3); assertEquals(groups[1][0].toString(), "+++"); assertEquals(groups[2][0].toString(), "13:17:11"); }
public void test29() throws PatternCompiler_E, IOException { // ±ß½ç²âÊÔ.²âÊÔÕýÔò±í´ïʽµÄ¸÷¸öÌØÊâ×Ö·û init( "t423tredf*~+~?~.~|~3~a~\r~\n~ ~&~_~^~fdafd", "\\*~\\+~\\?~\\.~\\|~\\d~\\D~\\r~\\n~\\s~\\S~\\w~\\W~"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "*~+~?~.~|~3~a~\r~\n~ ~&~_~^~"); }
public void test42() throws PatternCompiler_E, IOException { init(" 123 456 789", "(?:\\s+(\\d+)){3}"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[1].length, 3); assertEquals(groups[1][0].toString(), "123"); assertEquals(groups[1][1].toString(), "456"); assertEquals(groups[1][2].toString(), "789"); }
public void test16() throws IOException { this.init("51516", "(5\\d+)+6"); this.find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "51516"); assertEquals(groups[1].length, 2); assertEquals(groups[1][0].toString(), "51"); assertEquals(groups[1][1].toString(), "51"); }
public void test17() throws IOException { this.init("ab de ;", "(?:(\\w+)\\s+)+;"); this.find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "ab de ;"); assertEquals(groups[1].length, 2); assertEquals(groups[1][0].toString(), "ab"); assertEquals(groups[1][1].toString(), "de"); }
public void test21() throws IOException { this.init("AB5773", "(ABC)*577"); this.find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); String str = groups[0][0].toString(); System.out.println("test6: " + str); assertEquals(groups[0][0].toString(), "577"); assertEquals(groups[1].length, 0); }
public void test23() throws IOException { this.init("TTTTABCABCABTTTE", "TT(ABC)*ABT+"); this.find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "TTABCABCABTTT"); assertEquals(groups[1].length, 2); assertEquals(groups[1][0].toString(), "ABC"); assertEquals(groups[1][1].toString(), "ABC"); }
public void test_base2() throws PatternCompiler_E, IOException { // ×Ö·ûÀà init("Here is thie text.", "[aeiou]"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "e"); init("#####888Here is the text.#####", "[\\w\\s\\.]+#"); find(); groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "888Here is the text.#"); init("#####888Here is the text.#####", "[A-Za-z\\s\\.]+#"); find(); groups = matcher.getMatched(); assertEquals(groups.length, 1); assertEquals(groups[0][0].toString(), "Here is the text.#"); }
public void test44() throws PatternCompiler_E, IOException { String str = " 0.02 0.13 0.15"; init(str, "(\\S+)\\s+(\\S+)\\s+(\\S+)\\0"); // matcher.setDefaultTimeout(500); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 4); assertEquals(groups[1][0].toString(), "0.02"); assertEquals(groups[2][0].toString(), "0.13"); assertEquals(groups[3][0].toString(), "0.15"); }
public void test36() throws PatternCompiler_E, IOException { init("abcabc", "((abc)+)*"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 3); assertEquals(groups[0][0].toString(), "abcabc"); assertEquals(groups[1].length, 1); assertEquals(groups[1][0].toString(), "abcabc"); assertEquals(groups[2].length, 2); assertEquals(groups[2][0].toString(), "abc"); assertEquals(groups[2][1].toString(), "abc"); }
public void test48() throws PatternCompiler_E, IOException { String str = " 2566 1 2 syslogd syslogd -m 26.4 root Jan31 24 S 00:00:51 13.5 root Jan31 24 S 00:00:51\n" + " 2848 1 0 gpm gpm -t imps2 -m 0.0 root Jan31 24 S 00:00:01\n"; init( str, "(\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\w+)\\s+(\\S.*)\\s+(\\d+\\.\\d+)\\s+(\\w+)\\s+(\\w+)\\s+\\d+\\s\\w\\s(\\d\\d:\\d\\d:\\d\\d)\\n)+\\0"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 11); assertEquals(groups[7][0].toString(), "13.5"); }
public void test15() throws IOException { String str = "ch\nzh\n"; this.init(str, "(?:(\\w+)\n)+"); this.find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "ch\nzh\n"); assertEquals(groups[1].length, 2); assertEquals(groups[1][0].toString(), "ch"); assertEquals(groups[1][1].toString(), "zh"); str = "ch\nzh\n######"; this.init(str, "(?:(\\w+)\n)+"); this.find(); groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "ch\nzh\n"); assertEquals(groups[1].length, 2); assertEquals(groups[1][0].toString(), "ch"); assertEquals(groups[1][1].toString(), "zh"); str = "ABC\nABC\n######"; this.init(str, "(?:(ABC)\n)+"); this.find(); groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "ABC\nABC\n"); assertEquals(groups[1].length, 2); assertEquals(groups[1][0].toString(), "ABC"); assertEquals(groups[1][1].toString(), "ABC"); str = "ABC\nABC\n######"; this.init(str, "(?:(ABC)\n)+#"); this.find(); groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[0][0].toString(), "ABC\nABC\n#"); assertEquals(groups[1].length, 2); assertEquals(groups[1][0].toString(), "ABC"); assertEquals(groups[1][1].toString(), "ABC"); }
public void test43() throws PatternCompiler_E, IOException { String str = "fdsfd\nfdasfd\nfdsfdf\n 0 0 18496 46292 148448 445248 0 0 0 108 130 235 2 6 92 83"; init(str, "(?:.*\\n){3}(?:\\s+(\\d+)){16}"); find(); Submatched[][] groups = matcher.getMatched(); assertEquals(groups.length, 2); assertEquals(groups[1].length, 16); assertEquals(groups[1][0].toString(), "0"); assertEquals(groups[1][1].toString(), "0"); assertEquals(groups[1][2].toString(), "18496"); assertEquals(groups[1][15].toString(), "83"); }