JAVAÕýÔò±í´ïʽ PatternºÍMatcher
JAVAÕýÔò±í´ïʽ--PatternºÍMatcher
×÷Õߣº³Â¹ã¼Ñ ÎÄÕÂÀ´Ô´£ºwww.fooldock.com
·¢²¼ÈÕÆÚ£º2004Äê11ÔÂ19ÈÕ ä¯ÀÀ´ÎÊý£º2585´Î
ÏÖÔÚJDK1.4ÀïÖÕÓÚÓÐÁË×Ô¼ºµÄÕýÔò±í´ïʽAPI°ü£¬JAVA³ÌÐòÔ±¿ÉÒÔÃâÈ¥ÕÒµÚÈý·½ÌṩµÄÕýÔò±í´ïʽ¿âµÄÖÜÕÛÁË£¬ÎÒÃÇÏÖÔÚ¾ÍÂíÉÏÀ´Á˽âÒ»ÏÂÕâ¸öSUNÌṩµÄ³ÙÀ´¶÷Îï- -¶ÔÎÒÀ´ËµÈ·ÊµÈç´Ë¡£
1.¼ò½é£º
java.util.regexÊÇÒ»¸öÓÃÕýÔò±í´ïʽËù¶©ÖƵÄģʽÀ´¶Ô×Ö·û´®½øÐÐÆ¥Å乤×÷µÄÀà¿â°ü¡£
Ëü°üÀ¨Á½¸öÀࣺPatternºÍMatcher Pattern Ò»¸öPatternÊÇÒ»¸öÕýÔò±í´ïʽ¾±àÒëºóµÄ±íÏÖģʽ¡£
Matcher Ò»¸öMatcher¶ÔÏóÊÇÒ»¸ö״̬»úÆ÷£¬ËüÒÀ¾ÝPattern¶ÔÏó×öΪƥÅäģʽ¶Ô×Ö·û´®Õ¹¿ªÆ¥Åä¼ì²é¡£
Ê×ÏÈÒ»¸öPatternʵÀý¶©ÖÆÁËÒ»¸öËùÓÃÓï·¨ÓëPERLµÄÀàËƵÄÕýÔò±í´ïʽ¾±àÒëºóµÄģʽ£¬È»ºóÒ»¸öMatcherʵÀýÔÚÕâ¸ö¸ø¶¨µÄPatternʵÀýµÄģʽ¿ØÖÆϽøÐÐ×Ö·û´®µÄÆ¥Å乤×÷¡£
ÒÔÏÂÎÒÃǾͷֱðÀ´¿´¿´ÕâÁ½¸öÀࣺ
2.PatternÀà:
PatternµÄ·½·¨ÈçÏ£º static Pattern compile(String regex)
½«¸ø¶¨µÄÕýÔò±í´ïʽ±àÒë²¢¸³Óè¸øPatternÀà
static Pattern compile(String regex, int flags)
ͬÉÏ£¬µ«Ôö¼Óflag²ÎÊýµÄÖ¸¶¨£¬¿ÉÑ¡µÄflag²ÎÊý°üÀ¨£ºCASE INSENSITIVE,MULTILINE,DOTALL,UNICODE CASE£¬ CANON EQ
int flags()
·µ»Øµ±Ç°PatternµÄÆ¥Åäflag²ÎÊý.
Matcher matcher(CharSequence input)
Éú³ÉÒ»¸ö¸ø¶¨ÃüÃûµÄMatcher¶ÔÏó
static boolean matches(String regex, CharSequence input)
±àÒë¸ø¶¨µÄÕýÔò±í´ïʽ²¢ÇÒ¶ÔÊäÈëµÄ×Ö´®ÒÔ¸ÃÕýÔò±í´ïʽΪģ¿ªÕ¹Æ¥Åä,¸Ã·½·¨ÊʺÏÓÚ¸ÃÕýÔò±í´ïʽֻ»áʹÓÃÒ»´ÎµÄÇé¿ö£¬Ò²¾ÍÊÇÖ»½øÐÐÒ»´ÎÆ¥Å乤×÷£¬ÒòΪÕâÖÖÇé¿öϲ¢²»ÐèÒªÉú³ÉÒ»¸öMatcherʵÀý¡£
String pattern()
·µ»Ø¸ÃPatter¶ÔÏóËù±àÒëµÄÕýÔò±í´ïʽ¡£
String[] split(CharSequence input)
½«Ä¿±ê×Ö·û´®°´ÕÕPatternÀïËù°üº¬µÄÕýÔò±í´ïʽΪģ½øÐзָ
String[] split(CharSequence input, int limit)
×÷ÓÃͬÉÏ£¬Ôö¼Ó²ÎÊýlimitÄ¿µÄÔÚÓÚÒªÖ¸¶¨·Ö¸îµÄ¶ÎÊý£¬È罫limiÉèΪ2£¬ÄÇôĿ±ê×Ö·û´®½«¸ù¾ÝÕýÔò±í´ïʽ·ÖΪ¸îΪÁ½¶Î¡£
Ò»¸öÕýÔò±í´ïʽ£¬Ò²¾ÍÊÇÒ»´®ÓÐÌض¨ÒâÒåµÄ×Ö·û£¬±ØÐëÊ×ÏÈÒª±àÒ
Ïà¹ØÎĵµ£º
JavaỊ̈߳ºÏ̵߳ĵ÷¶È-ÐÝÃß
JavaÏ̵߳÷¶ÈÊÇJava¶àÏ̵߳ĺËÐÄ£¬Ö»ÓÐÁ¼ºÃµÄµ÷¶È£¬²ÅÄܳä·Ö·¢»ÓϵͳµÄÐÔÄÜ£¬Ìá¸ß³ÌÐòµÄÖ´ÐÐЧÂÊ¡£
ÕâÀïÒªÃ÷È·µÄÒ»µã£¬²»¹Ü³ÌÐòÔ±Ôõô±àдµ÷¶È£¬Ö»ÄÜ×î´óÏ޶ȵÄÓ°ÏìÏß³ÌÖ´ÐеĴÎÐò£¬¶ø²»ÄÜ×öµ½¾«×¼¿ØÖÆ¡£
Ïß³ÌÐÝÃßµÄÄ¿µÄÊÇʹÏß³ÌÈóöCPUµÄ×î¼òµ¥µÄ×ö·¨Ö®Ò»£¬Ïß³ÌÐÝÃß ......
import
java
.io.BufferedReader;
import
java
.io.FileInputStream;
import
java
.io.FileNotFoundException;
import
java
.io.FileOutputStream;
import
java
.io.IOException;
import
java
. ......
·½·¨Ò»£º
SimpleDateFormat formatter =
new
SimpleDateFormat(
"yyyyMMdd"
);
Date currentTime =
new
java.util.Date();
//
µÃµ½µ±Ç°ÏµÍ³Ê±¼ä
long
now = curr ......
ÔÚÍøÉÏÕÒÁ˼¸¸öÓÃjava»ñÈ¡±¾»úIPµØÖ·µÄ´úÂ룬·¢ÏÖ¶¼ÉÙ¶¼ÓÐЩ²»ÍêÃÀ£¬×Ô¼ºÕûÀíÁËÒ»ÏÂ.ͻȻ֮¼äºÜÏë°Ñ×Ô¼ºµÄIPµØÖ·¸ø»ñÈ¡ÁË£¬ËäÈ»ÓÃϵͳ×Ô´øÃüÁî¿ÉÒԵõ½£¬µ«×Ô¼ºÏëдһ¸ö³ÌÐò»ñȡһϣ¬µ½ÍøÉÏËÑË÷ÁËÒ»ÏÂjava»ñÈ¡±¾»úIPµØÖ·µÄ·½·¨£¬½á¹û¾ÓÈ»·¢ÏÖûÓÐÒ»¸öÊÇ¿ÉÒÔÓõģ¬ÆøµÄÎÒÀÏÈ˼ÒÍÂѪ£¬
ÕâЩÈ˱Õ×ÅÑÛ¾¦Ð´³ÌÐò£¬Ð´ÍêÁ˾ÍÍùÍøÉ ......