ͨÅä·ûÓÐÄÄЩ
ͨÅä·ûÊÇÆ¥Åä×Ö·û´®Ê±Ê¹ÓõÄÌØÊâ×Ö·û£¬ÌåÏÖí§Òâ×Ö·û»ò×Ö·ûÐòÁС£ÆäÀàÐÍ°üÀ¨£ºÐǺŠ(*)£ºí§ÒâÊýÄ¿µÄí§Òâ×Ö·ûÎʺŠ(?)£ºµ¥¸öí§Òâ×Ö·û·½À¨ºÅ ([])£ºÖ¸¶¨×Ö·û¹æÄ£Äڵĵ¥¸ö×Ö·ûÁ¬×Ö·û (-)£ºÖ¸¶¨×Ö·û¹æÄ£ÄÚµÄËùÓÐ×Ö·û
ʲôÊÇͨÅä·û£¿
ͨÅä·ûÊÇÒ»ÖÖÌØÊâ×Ö·û£¬ÓÃÔÚ×Ö·û´®Æ¥ÅäÖУ¬ÌåÏÖí§Òâ×Ö·û»ò×Ö·ûÐòÁС£
ͨÅä·ûÀàÐÍ£º
ÐǺŠ(*)£ºÆ¥Åäí§ÒâÊýÄ¿µÄí§Òâ×Ö·û£¬°üÀ¨¿Õ×Ö·û´®¡£
ÎʺŠ(?)£ºÆ¥Åäµ¥¸öí§Òâ×Ö·û¡£
·½À¨ºÅ ([])£ºÆ¥ÅäÖ¸¶¨×Ö·û¹æÄ£Äڵĵ¥¸ö×Ö·û¡£
Á¬×Ö·û (-)£ºÆ¥ÅäÖ¸¶¨µÄ×Ö·û¹æÄ£ÄÚµÄËùÓÐ×Ö·û¡£
ͨÅä·ûÓ÷¨£º
ͨÅä·ûÆÕ±éÓÃÓÚÎļþËÑË÷¡¢Îı¾±à¼ºÍ±à³ÌµÈ³¡¾°¡£ÒÔÏÂÊǼ¸¸ö³£¼ûÓ÷¨£º
ÎļþËÑË÷£º
*.txt£º²éÕÒËùÓкó׺Ϊ “.txt” µÄÎļþ¡£
?.*£º²éÕÒËùÓÐÒÔí§Òâ×Ö·û¿ªÍ·£¬ºó¸úí§ÒâÊýÄ¿×Ö·ûµÄÎļþ¡£
Îı¾±à¼£º
find *ing£º²éÕÒ°üÀ¨ “ing” ×Ö´®µÄÎı¾¡£
replace ? with a£º½«Îı¾ÖеÄËùÓе¥¸öÎʺÅ×Ö·ûÌ滻Ϊ “a”¡£
±à³Ì£º
Pattern.matches(“*foo”)£º¼ì²é×Ö·û´®ÊÇ·ñÒÔ “foo” ×îºó¡£
String.replaceAll(“a?”, “b”)£º½«×Ö·û´®ÖÐËùÓзºÆð “a” »ò “aa” µÄλÖÃÌ滻Ϊ “b”¡£
×¢ÖØÊÂÏ
ͨÅä·ûͨ³£²»Çø·Ö¾Þϸд¡£
ÌØÊâ×Ö·û£¨ÈçµãºÅ¡¢Ð±¸Ü£©ÔÚͨÅä·ûÖÐÐèҪתÒ壨Èç \.¡¢\/£©¡£
ͨÅä·ûµÄʹÓÿÉÄÜÒòÓ¦ÓóÌÐò»ò±à³ÌÓïÑÔ¶øÒì¡£Çë²Î¿¼Ïà¹ØÎĵµÒÔ»ñÈ¡ÏêϸÓ÷¨¡£
ÒÔÉϾÍÊÇͨÅä·ûÓÐÄÄЩµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡