JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 技巧文件  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
己加入精華區
by browser at 2008-03-10 11:29
本主題所含的標籤
作者 Re:Java Regular Expression的學習筆記 [Re:kebin_liu]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2005-10-13 02:06 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
kebin_liu wrote:
...
實例 "c|Car"(等同於"[cC]ar")相符字串是"car"或"Car"。
...
最後誰能幫忙解釋一下"(?>X)",因為我實在分不出來他和(?:X)有什麼差別....


(1) Typo Error. It should be:
實例 "(?:c|C)ar"(等同於"[cC]ar")相符字串是"car"或"Car"。
( "c|Car" will match "c" or "Car" )

And although (c|C) is the same as [cC], the performance may different, check:
http://www.javaworld.com.tw/jute/post/view?bid=5&id=43615&sty=3&age=0&tpg=1&ppg=1#43615

(2) Java API said (?>X) X, as an independent, non-capturing group
In fact, the (?>X) is *Atomic grouping*,
Text matched within the group is never backtracked into, even if this leads to a match failure.
Here is my example that lets you know the differenct between (?>X) and (?:X)
1
2
3
4
5
6
7
8
9
import java.util.regex.*;
public class Test {
    public static void main(String[] args) throws Exception {
        System.out.println(Pattern.matches("(?>[ab]*)\\w\\w", "aabbcc")); # true
        System.out.println(Pattern.matches("(?:[ab]*)\\w\\w", "aabbcc")); # true
        System.out.println(Pattern.matches("(?>[ab]*)\\w\\w", "aabbaa")); # false!
        System.out.println(Pattern.matches("(?:[ab]*)\\w\\w", "aabbaa")); # true
    }
}


T55555 edited on 2005-10-13 03:14
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
276812 [精華] Java Regular Expression的學習筆記 kebin_liu 9187 2005-10-12 23:42
266834 Re:Java Regular Expression的學習筆記 T55555 1209 2005-10-13 02:06
266359 Re:Java Regular Expression的學習筆記 kebin_liu 277 2005-10-13 16:23
264764 Re:Java Regular Expression的學習筆記 emt2a7 582 2006-05-17 11:32
237626 Re:Java Regular Expression的學習筆記 tommy567332 178 2008-07-22 14:42
237542 Re:Java Regular Expression的學習筆記 kebin_liu 509 2008-07-22 17:37
238012 Re:Java Regular Expression的學習筆記 tommy567332 343 2008-07-23 08:54
78142 Re:Java Regular Expression的學習筆記 KiahStarck 57 2015-06-28 17:00
» JWorld@TW »  Java 技巧文件

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8