ÕýÔò±í´ïʽѧϰ×ܽá, ¸½javaÔ´Âë
×éµÄ¸ÅÄî, ÌáÈ¡×éÐÅÏ¢
/**
* ÕýÔò±í´ïʽ¿ÉÒÔ»®·Ö²»Í¬µÄ×é,È¡³ö×éµÄÃû³Æ,À¨ºÅ¼´¿É, ¼´ËùνµÄ²¶»ñ×é
* 1. Ïà¹Ø֪ʶ: ²»²¶»ñÓÃ(?:expression) ±íʾÕâ×é²»ÐèÒª²¶»ñ
*
*
*/
public static void groupTest() {
String src = "xxxxxxxxxx2009-1-17-19-07-16yyyyy2001-02-18-19-07-16q";
String regex = "(\\w{4})(\\d{4}-\\d{1,2}-\\d{1,2}-\\d{1,2}-\\d{1,2}-\\d{1,2})";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(src);
displayMatchResult(matcher);
}
»ò¹ØϵµÄ±í´ï
/**
* 1. µ¥¸ö×Ö·û»òÕßÊý×ÖµÄ"»ò¹Øϵ"ÓÃ[]¼´¿É, ÕâÀï²»×öչʾ
* 2. ¶à¸ö×Ö·ûµÄ"»ò¹Øϵ"ÓÃÀ¨ºÅչʾ
* 3. ÌáÈ¡À¨ºÅµÄÄÚÈÝ, Çë¿´ÏÂÃæµÄÀý×Ó, ¹Ø×¢groupµÄindex
* 4. ÕâÀïµÄGroup¿ÉÒÔ²»²¶»ñ£¬²»²¶»ñµÄ·½Ê½ÊÇ(?:expression)
* 5. ÕâÀïÍƳöµÄÎÊÌâÊÇ:"·ÇÂß¼¹ØϵÔõô¸ã"(ÓëÂß¼¹Øϵ¾ÍËãÁË, ĬÈϵĶ¼ÊÇÓëÂß¼¹Øϵ)
* 6. ·Ç¹Øϵ, ¹éÀൽ"Áã¿í¶È"ÖÐ
*
*/
public static void groupOr_Nested()
{
String src = "x1111abcxxxyyy";
String regex = "((?:x1111|y2222)abc)xxx";
//String regex = "((x1111|y2222)abc)xxx";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(src);
displayMatchResult(matcher);
}
Ì°À·ºÍ·ÇÌ°À·Æ¥Åä
/**
* Ì°À·Æ¥ÅäºÍ·ÇÌ°À·Æ¥ÅäµÄ±È½Ï
* ÕâÊÇÒ»¸ö¼Ó²»¼ÓÎʺõÄÎÊÌâÁË
*/
public static void greedCompare()
{
String src = "<p class=\"author\"> <strong>admin </strong></strong> ·¢±íÓÚ 2009-5-14 16:49 </p><h3>ÌáÈ¡Ìû×ÓÄÚÈÝ </h3>“ÌáÈ¡Õâ¾ä»°”<br /> <br />";
/**·ÇÌ°À·Æ¥ÅäÓÃÏÂÃæ*/
//String regex = "<strong>(.*?)</strong>";
/**Ì°À·Æ¥ÅäÓÃÏÂÃæ */
String regex = "<strong>(.*)</strong>";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(src);
displayMatchResult(matcher);
}
Ìæ»»×Ö·û
/**
* Ìæ»», ¸Ã·½·¨ºÜË®, ¼òµ¥µÄ¿ÉÓÃ, ¸´ÔÓµÄ
* Ó¦¸Ãͨ¹ýmatch.star(groupIndex)À´ÕÒλÖñȽϷ½±ã
*/
public static void replaceMatch()
{
String src = "xxxxxxxxxx200
Ïà¹ØÎĵµ£º
ListµÄÓ÷¨
List°üÀ¨List½Ó¿ÚÒÔ¼°List½Ó¿ÚµÄËùÓÐʵÏÖÀà¡£ÒòΪList½Ó¿ÚʵÏÖÁËCollection½Ó¿Ú£¬ËùÒÔList½Ó¿ÚÓµÓÐCollection½Ó¿ÚÌṩµÄËùÓг£Ó÷½·¨£¬ÓÖÒòΪListÊÇÁбíÀàÐÍ£¬ËùÒÔList½Ó¿Ú»¹ÌṩÁËһЩÊʺÏÓÚ×ÔÉíµÄ³£Ó÷½·¨£¬Èç±í1Ëùʾ¡£
±í1 List½Ó¿Ú¶¨ÒåµÄ³£Ó÷½·¨¼°¹¦ÄÜ
´Ó±í1¿ÉÒÔ¿´³ö£¬List½Ó¿ÚÌṩµÄÊʺÏÓÚ×ÔÉíµÄ ......
Ôڳɹ¦ÊµÏÖJavaµ÷ÓÃC++Ö®ºó£¬½ÓÏÂÀ´Ïëµ½ÄÜ·ñͨ¹ýJNAʵÏÖJavaµ÷ÓÃFortran£¬½ñÌìÊÔÑéÁËһϣ¬»¹ÊDZȽÏÈÝÒ׵ġ£
ÍøÉÏÓÐÒ»¸öJavaµ÷ÓÃF95µÄÀý×Ó£¬µ«ÊÇÎÒ¿¼ÂDz»½öҪʵÏÖF95µÄµ÷Ó㬻¹ÒªÊµÏÖF77µÄµ÷Óã¬ËùÒÔ·ÑÁËһЩÖÜÕÛ¡£
ÎÊÌâµÄ¹Ø¼üÔÚÓÚF77Ϊ¹ý³ÌÃû×Ô¶¯Ìí¼ÓÁËÒ»¸öβ²¿µÄÏ»®Ïߣ¬ËùÒÔsub1Õâ¸ö¹ý³Ì£¬µ½JavaÒ»¶Ë£¬¾Í±ä³ÉÁËsub1_£¬ ......
Java codeFormat ft=Format.getRawFormat();
ft.setEncoding("utf-8");
ft.setIndent(" ");//ÉèÖÃËõ½ø
XMLOutputter outputter=new XMLOutputter(ft);//ÉèÖÃXML¸ñʽ
Õâλ˵µÄ²»´í£»
ÔÚieÀïÃ棬ËüÄÜ°Ñxml×Ô¶¯½âÎö³ÆÊ÷Ðνṹ£¬ËùÒÔ¿´ÆðÀ´Ã»ÎÊÌ⣬ÔÚ¼Çʱ¾ÀïÃ棬¾Í²»ÐÐÁ ......
ͨ¹ý Groovy ½øÐÐÑ»·
ͬ´ó¶àÊý½Å±¾ÓïÑÔÒ»Ñù£¬Groovy ¾³£±»Ðû´«ÎªÉú²úÁ¦¸ü¸ß µÄ Java ÓïÑÔÌæ´úÆ·¡£ÄúÒѾ¿´µ½ÁË Groovy ȱÉÙÀàÐÍÄܹ»ÈçºÎ¼õÉÙ´ò×Ö¹¤×÷¡£ÔÚÕâÒ»½Ú£¬½«´´½¨²¢ÊÔÓÃÒ»¸ö repeat º¯Êý¡£ÔÚÕâ¸ö¹ý³ÌÖУ¬½«½øÒ»²½Ì½Ë÷ Groovy Ìá¸ßЧÂʵķ½Ê½¡£
¸üºÃ¡¢¸ü¶ÌµÄÑ»·
ÏÂÃæÕâÖÖ·½·¨¿ÉÒÔ¸üºÃµØ¸ÐÊÜ Groovy ȱ·¦ÀàÐ͵ĺà ......
1¡¢²âÊÔ·½·¨ÈçÏ£º
public static String toUtf8(String str) {
return new String(str.getBytes("UTF-8"),"UTF-8"):
&nb ......