Package COM. CG. tests; import Java. util. regEx. matcher; import Java. util. regEx. pattern; import Org. JUnit. test; public class testpatternmatcher {@ testpublic void testreplaceall () {string S = "Hello world... "; string S2 = S. replaceall ("\\. "," "); system. out. println (S2); string S3 = S. replaceall ("\ s", ""); system. out. println (S3); string slinesep = system. getproperty ("line. separator "); string S4 =" abcdefg "+ slinesep + "China"; system. out. println (S4); system. out. println (s4.replace (slinesep, "newline"); string S5 = "1985-01-17, born on this date 23423-2384-"; pattern = pattern. compile ("\ D +"); matcher M = pattern. matcher (S5); While (M. find () {system. out. println (M. group () + "[" + M. start () + "]-[" + M. end () + "]");} system. out. println ("##################"); string S6 = "just do it ~! 123abc @ 1234efg "; // pattern PDO = pattern. compile ("do \ s (do \ s) +"); pattern PDO = pattern. compile ("\ D + (\ W +)"); matcher MDO = PDO. matcher (s6); While (MDO. find () {for (INT I = 0; I <MDO. groupcount (); I ++) {// system. out. println (MDO. group () + "[" + MDO. start () + "]-[" // + MDO. end () + "]"); system. out. println (I + ":" + MDO. group (I) ;}}@ testpublic void testgreedy () {string html = "<Table> <tr> <TD> 123 ksdjfsld </TD> <TD> 34243 kdljsfkldsf </TD> kdlfjsdf </tr> </table "; matcher M = pattern. compile ("<TD> (\ D +) (\ W +) </TD> "). matcher (HTML); // non-Greedy mode while (M. find () {int CNT = m. groupcount (); system. out. println (CNT); For (INT I = 0; I <= CNT; I ++) {system. out. println ("group" + I + ":" + M. group (I) ;}}@ testpublic void testgreedy2 () {string html = "klsdjfl83943875921_ksjd"; matcher M = pattern. compile ("\ D +? "). Matcher (HTML); // non-Greedy mode while (M. Find () {system. Out. println (M. Group ());}}}