posts - 19, comments - 1, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          2006年10月10日

          正則表達式是煩瑣的,但是強大的,學會之后的應用會讓你除了提高效率外,會給你帶來絕對的成就感。只要認真去閱讀這些資料,加上應用的時候進行一定的參考,掌握正則表達式不是問題。

          索引

          1. 引子
          2. 正則表達式的歷史
          3. 正則表達式定義

          3.1 普通字符
          3.2 非打印字符
          3.3 特殊字符
          3.4 限定符
          3.5 定位符
          3.6 選擇
          3.7 后向引用

          4. 各種操作符的運算優先級
          5. 全部符號解釋
          6. 部分例子
          7. 正則表達式匹配規則

          7.1 基本模式匹配
          7.2 字符簇
          7.3 確定重復出現

          1. 引子
            目前,正則表達式已經在很多軟件中得到廣泛的應用,包括*nix(Linux, Unix等),HP等操作系統,PHP,C#,Java等開發環境,以及很多的應用軟件中,都可以看到正則表達式的影子。

            正則表達式的使用,可以通過簡單的辦法來實現強大的功能。為了簡單有效而又不失強大,造成了正則表達式代碼的難度較大,學習起來也不是很容易,所以需要付出一些努力才行,入門之后參照一定的參考,使用起來還是比較簡單有效的。

          例子: ^.+@.+\\..+$

            這樣的代碼曾經多次把我自己給嚇退過。可能很多人也是被這樣的代碼給嚇跑的吧。繼續閱讀本文將讓你也可以自由應用這樣的代碼。

            注意:這里的第7部分跟前面的內容看起來似乎有些重復,目的是把前面表格里的部分重新描述了一次,目的是讓這些內容更容易理解。

          2. 正則表達式的歷史
            正則表達式的“祖先”可以一直上溯至對人類神經系統如何工作的早期研究。Warren McCulloch 和 Walter Pitts 這兩位神經生理學家研究出一種數學方式來描述這些神經網絡。
            1956 年, 一位叫 Stephen Kleene 的數學家在 McCulloch 和 Pitts 早期工作的基礎上,發表了一篇標題為“神經網事件的表示法”的論文,引入了正則表達式的概念。正則表達式就是用來描述他稱為“正則集的代數”的表達式,因此采用“正則表達式”這個術語。

            隨后,發現可以將這一工作應用于使用 Ken Thompson 的計算搜索算法的一些早期研究,Ken Thompson 是 Unix 的主要發明人。正則表達式的第一個實用應用程序就是 Unix 中的 qed 編輯器。

            如他們所說,剩下的就是眾所周知的歷史了。從那時起直至現在正則表達式都是基于文本的編輯器和搜索工具中的一個重要部分。

           

          3. 正則表達式定義
            正則表達式(regular expression)描述了一種字符串匹配的模式,可以用來檢查一個串是否含有某種子串、將匹配的子串做替換或者從某個串中取出符合某個條件的子串等。

          列目錄時, dir *.txt或ls *.txt中的*.txt就不是一個正則表達式,因為這里*與正則式的*的含義是不同的。
            正則表達式是由普通字符(例如字符 a 到 z)以及特殊字符(稱為元字符)組成的文字模式。正則表達式作為一個模板,將某個字符模式與所搜索的字符串進行匹配。

          3.1 普通字符
            由所有那些未顯式指定為元字符的打印和非打印字符組成。這包括所有的大寫和小寫字母字符,所有數字,所有標點符號以及一些符號。

          3.2 非打印字符
          字符 含義
          \cx 匹配由x指明的控制字符。例如, \cM 匹配一個 Control-M 或回車符。x 的值必須為 A-Z 或 a-z 之一。否則,將 c 視為一個原義的 ‘c’ 字符。
          \f 匹配一個換頁符。等價于 \x0c 和 \cL。
          \n 匹配一個換行符。等價于 \x0a 和 \cJ。
          \r 匹配一個回車符。等價于 \x0d 和 \cM。
          \s 匹配任何空白字符,包括空格、制表符、換頁符等等。等價于 [ \f\n\r\t\v]。
          \S 匹配任何非空白字符。等價于 [^ \f\n\r\t\v]。
          \t 匹配一個制表符。等價于 \x09 和 \cI。
          \v 匹配一個垂直制表符。等價于 \x0b 和 \cK。

           
          3.3 特殊字符
            所謂特殊字符,就是一些有特殊含義的字符,如上面說的”*.txt”中的*,簡單的說就是表示任何字符串的意思。如果要查找文件名中有*的文件,則需要對*進行轉義,即在其前加一個\。ls \*.txt。正則表達式有以下特殊字符。
           

          特別字符 說明
          $ 匹配輸入字符串的結尾位置。如果設置了 RegExp 對象的 Multiline 屬性,則 $ 也匹配 ‘\n’ 或 ‘\r’。要匹配 $ 字符本身,請使用 \$。
          ( ) 標記一個子表達式的開始和結束位置。子表達式可以獲取供以后使用。要匹配這些字符,請使用 \( 和 \)。
          * 匹配前面的子表達式零次或多次。要匹配 * 字符,請使用 \*。
          + 匹配前面的子表達式一次或多次。要匹配 + 字符,請使用 \+。
          . 匹配除換行符 \n之外的任何單字符。要匹配 .,請使用 \。
          [ 標記一個中括號表達式的開始。要匹配 [,請使用 \[。
          ? 匹配前面的子表達式零次或一次,或指明一個非貪婪限定符。要匹配 ? 字符,請使用 \?。
          \ 將下一個字符標記為或特殊字符、或原義字符、或向后引用、或八進制轉義符。例如, ‘n’ 匹配字符 ‘n’。’\n’ 匹配換行符。序列 ‘\\’ 匹配 “\”,而 ‘\(’ 則匹配 “(”。
          ^ 匹配輸入字符串的開始位置,除非在方括號表達式中使用,此時它表示不接受該字符集合。要匹配 ^ 字符本身,請使用 \^。
          { 標記限定符表達式的開始。要匹配 {,請使用 \{。
          | 指明兩項之間的一個選擇。要匹配 |,請使用 \|。

            構造正則表達式的方法和創建數學表達式的方法一樣。也就是用多種元字符與操作符將小的表達式結合在一起來創建更大的表達式。正則表達式的組件可以是單個的字符、字符集合、字符范圍、字符間的選擇或者所有這些組件的任意組合。
           

          3.4 限定符
            限定符用來指定正則表達式的一個給定組件必須要出現多少次才能滿足匹配。有*或+或?或{n}或{n,}或{n,m}共6種。
          *、+和?限定符都是貪婪的,因為它們會盡可能多的匹配文字,只有在它們的后面加上一個?就可以實現非貪婪或最小匹配。
            正則表達式的限定符有:
            字符 描述
          * 匹配前面的子表達式零次或多次。例如,zo* 能匹配 “z” 以及 “zoo”。* 等價于{0,}。
          + 匹配前面的子表達式一次或多次。例如,’zo+’ 能匹配 “zo” 以及 “zoo”,但不能匹配 “z”。+ 等價于 {1,}。
          ? 匹配前面的子表達式零次或一次。例如,”do(es)?” 可以匹配 “do” 或 “does” 中的”do” 。? 等價于 {0,1}。
          {n} n 是一個非負整數。匹配確定的 n 次。例如,’o{2}’ 不能匹配 “Bob” 中的 ‘o’,但是能匹配 “food” 中的兩個 o。
          {n,} n 是一個非負整數。至少匹配n 次。例如,’o{2,}’ 不能匹配 “Bob” 中的 ‘o’,但能匹配 “foooood” 中的所有 o。’o{1,}’ 等價于 ‘o+’。’o{0,}’ 則等價于 ‘o*’。
          {n,m} m 和 n 均為非負整數,其中n <= m。最少匹配 n 次且最多匹配 m 次。例如,”o{1,3}” 將匹配 “fooooood” 中的前三個 o。’o{0,1}’ 等價于 ‘o?’。請注意在逗號和兩個數之間不能有空格。

          3.5 定位符
            用來描述字符串或單詞的邊界,^和$分別指字符串的開始與結束,\b描述單詞的前或后邊界,\B表示非單詞邊界。不能對定位符使用限定符。

          3.6 選擇
            用圓括號將所有選擇項括起來,相鄰的選擇項之間用|分隔。但用圓括號會有一個副作用,是相關的匹配會被緩存,此時可用?:放在第一個選項前來消除這種副作用。
            其中?:是非捕獲元之一,還有兩個非捕獲元是?=和?!,這兩個還有更多的含義,前者為正向預查,在任何開始匹配圓括號內的正則表達式模式的位置來匹配搜索字符串,后者為負向預查,在任何開始不匹配該正則表達式模式的位置來匹配搜索字符串。

          3.7 后向引用
            對一個正則表達式模式或部分模式兩邊添加圓括號將導致相關匹配存儲到一個臨時緩沖區中,所捕獲的每個子匹配都按照在正則表達式模式中從左至右所遇到的內容存儲。存儲子匹配的緩沖區編號從 1 開始,連續編號直至最大 99 個子表達式。每個緩沖區都可以使用 ‘\n’ 訪問,其中 n 為一個標識特定緩沖區的一位或兩位十進制數。
            可以使用非捕獲元字符 ‘?:’, ‘?=’, or ‘?!’ 來忽略對相關匹配的保存。

          4. 各種操作符的運算優先級
            相同優先級的從左到右進行運算,不同優先級的運算先高后低。各種操作符的優先級從高到低如下:
            操作符 描述
          \ 轉義符
          (), (?:), (?=), [] 圓括號和方括號
          *, +, ?, {n}, {n,}, {n,m} 限定符
          ^, $, \anymetacharacter 位置和順序
          | “或”操作

          5. 全部符號解釋

          字符 描述
          \ 將下一個字符標記為一個特殊字符、或一個原義字符、或一個 向后引用、或一個八進制轉義符。例如,’n’ 匹配字符 “n”。’\n’ 匹配一個換行符。序列 ‘\\’ 匹配 “\” 而 “\(” 則匹配 “(”。
          ^ 匹配輸入字符串的開始位置。如果設置了 RegExp 對象的 Multiline 屬性,^ 也匹配 ‘\n’ 或 ‘\r’ 之后的位置。
          $ 匹配輸入字符串的結束位置。如果設置了RegExp 對象的 Multiline 屬性,$ 也匹配 ‘\n’ 或 ‘\r’ 之前的位置。
          * 匹配前面的子表達式零次或多次。例如,zo* 能匹配 “z” 以及 “zoo”。* 等價于{0,}。
          + 匹配前面的子表達式一次或多次。例如,’zo+’ 能匹配 “zo” 以及 “zoo”,但不能匹配 “z”。+ 等價于 {1,}。
          ? 匹配前面的子表達式零次或一次。例如,”do(es)?” 可以匹配 “do” 或 “does” 中的”do” 。? 等價于 {0,1}。
          {n} n 是一個非負整數。匹配確定的 n 次。例如,’o{2}’ 不能匹配 “Bob” 中的 ‘o’,但是能匹配 “food” 中的兩個 o。
          {n,} n 是一個非負整數。至少匹配n 次。例如,’o{2,}’ 不能匹配 “Bob” 中的 ‘o’,但能匹配 “foooood” 中的所有 o。’o{1,}’ 等價于 ‘o+’。’o{0,}’ 則等價于 ‘o*’。
          {n,m} m 和 n 均為非負整數,其中n <= m。最少匹配 n 次且最多匹配 m 次。例如,”o{1,3}” 將匹配 “fooooood” 中的前三個 o。’o{0,1}’ 等價于 ‘o?’。請注意在逗號和兩個數之間不能有空格。
          ? 當該字符緊跟在任何一個其他限制符 (*, +, ?, {n}, {n,}, {n,m}) 后面時,匹配模式是非貪婪的。非貪婪模式盡可能少的匹配所搜索的字符串,而默認的貪婪模式則盡可能多的匹配所搜索的字符串。例如,對于字符串 “oooo”,’o+?’ 將匹配單個 “o”,而 ‘o+’ 將匹配所有 ‘o’。
          . 匹配除 “\n” 之外的任何單個字符。要匹配包括 ‘\n’ 在內的任何字符,請使用象 ‘[.\n]’ 的模式。
          (pattern) 匹配 pattern 并獲取這一匹配。所獲取的匹配可以從產生的 Matches 集合得到,在VBScript 中使用 SubMatches 集合,在JScript 中則使用 $0…$9 屬性。要匹配圓括號字符,請使用 ‘\(’ 或 ‘\)’。
          (?:pattern) 匹配 pattern 但不獲取匹配結果,也就是說這是一個非獲取匹配,不進行存儲供以后使用。這在使用 “或” 字符 (|) 來組合一個模式的各個部分是很有用。例如, ‘industr(?:y|ies) 就是一個比 ‘industry|industries’ 更簡略的表達式。
          (?=pattern) 正向預查,在任何匹配 pattern 的字符串開始處匹配查找字符串。這是一個非獲取匹配,也就是說,該匹配不需要獲取供以后使用。例如,’Windows (?=95|98|NT|2000)’ 能匹配 “Windows 2000″ 中的 “Windows” ,但不能匹配 “Windows 3.1″ 中的 “Windows”。預查不消耗字符,也就是說,在一個匹配發生后,在最后一次匹配之后立即開始下一次匹配的搜索,而不是從包含預查的字符之后開始。
          (?!pattern) 負向預查,在任何不匹配 pattern 的字符串開始處匹配查找字符串。這是一個非獲取匹配,也就是說,該匹配不需要獲取供以后使用。例如’Windows (?!95|98|NT|2000)’ 能匹配 “Windows 3.1″ 中的 “Windows”,但不能匹配 “Windows 2000″ 中的 “Windows”。預查不消耗字符,也就是說,在一個匹配發生后,在最后一次匹配之后立即開始下一次匹配的搜索,而不是從包含預查的字符之后開始
          x|y 匹配 x 或 y。例如,’z|food’ 能匹配 “z” 或 “food”。’(z|f)ood’ 則匹配 “zood” 或 “food”。
          [xyz] 字符集合。匹配所包含的任意一個字符。例如, ‘[abc]’ 可以匹配 “plain” 中的 ‘a’。
          [^xyz] 負值字符集合。匹配未包含的任意字符。例如, ‘[^abc]’ 可以匹配 “plain” 中的’p'。
          [a-z] 字符范圍。匹配指定范圍內的任意字符。例如,’[a-z]’ 可以匹配 ‘a’ 到 ‘z’ 范圍內的任意小寫字母字符。
          [^a-z] 負值字符范圍。匹配任何不在指定范圍內的任意字符。例如,’[^a-z]’ 可以匹配任何不在 ‘a’ 到 ‘z’ 范圍內的任意字符。
          \b 匹配一個單詞邊界,也就是指單詞和空格間的位置。例如, ‘er\b’ 可以匹配”never” 中的 ‘er’,但不能匹配 “verb” 中的 ‘er’。
          \B 匹配非單詞邊界。’er\B’ 能匹配 “verb” 中的 ‘er’,但不能匹配 “never” 中的 ‘er’。
          \cx 匹配由 x 指明的控制字符。例如, \cM 匹配一個 Control-M 或回車符。x 的值必須為 A-Z 或 a-z 之一。否則,將 c 視為一個原義的 ‘c’ 字符。
          \d 匹配一個數字字符。等價于 [0-9]。
          \D 匹配一個非數字字符。等價于 [^0-9]。
          \f 匹配一個換頁符。等價于 \x0c 和 \cL。
          \n 匹配一個換行符。等價于 \x0a 和 \cJ。
          \r 匹配一個回車符。等價于 \x0d 和 \cM。
          \s 匹配任何空白字符,包括空格、制表符、換頁符等等。等價于 [ \f\n\r\t\v]。
          \S 匹配任何非空白字符。等價于 [^ \f\n\r\t\v]。
          \t 匹配一個制表符。等價于 \x09 和 \cI。
          \v 匹配一個垂直制表符。等價于 \x0b 和 \cK。
          \w 匹配包括下劃線的任何單詞字符。等價于’[A-Za-z0-9_]’。
          \W 匹配任何非單詞字符。等價于 ‘[^A-Za-z0-9_]’。
          \xn 匹配 n,其中 n 為十六進制轉義值。十六進制轉義值必須為確定的兩個數字長。例如,’\x41′ 匹配 “A”。’\x041′ 則等價于 ‘\x04′ & “1″。正則表達式中可以使用 ASCII 編碼。.
          \num 匹配 num,其中 num 是一個正整數。對所獲取的匹配的引用。例如,’(.)\1′ 匹配兩個連續的相同字符。
          \n 標識一個八進制轉義值或一個向后引用。如果 \n 之前至少 n 個獲取的子表達式,則 n 為向后引用。否則,如果 n 為八進制數字 (0-7),則 n 為一個八進制轉義值。
          \nm 標識一個八進制轉義值或一個向后引用。如果 \nm 之前至少有 nm 個獲得子表達式,則 nm 為向后引用。如果 \nm 之前至少有 n 個獲取,則 n 為一個后跟文字 m 的向后引用。如果前面的條件都不滿足,若 n 和 m 均為八進制數字 (0-7),則 \nm 將匹配八進制轉義值 nm。
          \nml 如果 n 為八進制數字 (0-3),且 m 和 l 均為八進制數字 (0-7),則匹配八進制轉義值 nml。
          \un 匹配 n,其中 n 是一個用四個十六進制數字表示的 Unicode 字符。例如, \u00A9 匹配版權符號 (?)。

           

          6. 部分例子

          正則表達式 說明
          /\b([a-z]+) \1\b/gi 一個單詞連續出現的位置
          /(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/ 將一個URL解析為協議、域、端口及相對路徑
          /^(?:Chapter|Section) [1-9][0-9]{0,1}$/ 定位章節的位置
          /[-a-z]/ A至z共26個字母再加一個-號。
          /ter\b/ 可匹配chapter,而不能terminal
          /\Bapt/ 可匹配chapter,而不能aptitude
          /Windows(?=95 |98 |NT )/ 可匹配Windows95或Windows98或WindowsNT,當找到一個匹配后,從Windows后面開始進行下一次的檢索匹配。

          7. 正則表達式匹配規則
          7.1 基本模式匹配

            一切從最基本的開始。模式,是正規表達式最基本的元素,它們是一組描述字符串特征的字符。模式可以很簡單,由普通的字符串組成,也可以非常復雜,往往用特殊的字符表示一個范圍內的字符、重復出現,或表示上下文。例如:

          ^once

            這個模式包含一個特殊的字符^,表示該模式只匹配那些以once開頭的字符串。例如該模式與字符串”once upon a time”匹配,與”There once was a man from NewYork”不匹配。正如如^符號表示開頭一樣,$符號用來匹配那些以給定模式結尾的字符串。

          bucket$

            這個模式與”Who kept all of this cash in a bucket”匹配,與”buckets”不匹配。字符^和$同時使用時,表示精確匹配(字符串與模式一樣)。例如:

          ^bucket$

            只匹配字符串”bucket”。如果一個模式不包括^和$,那么它與任何包含該模式的字符串匹配。例如:模式

          once

          與字符串

          There once was a man from NewYork
          Who kept all of his cash in a bucket.

          是匹配的。

            在該模式中的字母(o-n-c-e)是字面的字符,也就是說,他們表示該字母本身,數字也是一樣的。其他一些稍微復雜的字符,如標點符號和白字符(空格、制表符等),要用到轉義序列。所有的轉義序列都用反斜杠(\)打頭。制表符的轉義序列是:\t。所以如果我們要檢測一個字符串是否以制表符開頭,可以用這個模式:

          ^\t

          類似的,用\n表示“新行”,\r表示回車。其他的特殊符號,可以用在前面加上反斜杠,如反斜杠本身用\\表示,句號.用\.表示,以此類推。

          7.2 字符簇

          在INTERNET的程序中,正規表達式通常用來驗證用戶的輸入。當用戶提交一個form以后,要判斷輸入的電話號碼、地址、EMAIL地址、信用卡號碼等是否有效,用普通的基于字面的字符是不夠的。

          所以要用一種更自由的描述我們要的模式的辦法,它就是字符簇。要建立一個表示所有元音字符的字符簇,就把所有的元音字符放在一個方括號里:

          [AaEeIiOoUu]

          這個模式與任何元音字符匹配,但只能表示一個字符。用連字號可以表示一個字符的范圍,如:

          [a-z] //匹配所有的小寫字母
          [A-Z] //匹配所有的大寫字母
          [a-zA-Z] //匹配所有的字母
          [0-9] //匹配所有的數字
          [0-9\.\-] //匹配所有的數字,句號和減號
          [ \f\r\t\n] //匹配所有的白字符

          同樣的,這些也只表示一個字符,這是一個非常重要的。如果要匹配一個由一個小寫字母和一位數字組成的字符串,比如”z2″、”t6″或”g7″,但不是”ab2″、”r2d3″ 或”b52″的話,用這個模式:

          ^[a-z][0-9]$

          盡管[a-z]代表26個字母的范圍,但在這里它只能與第一個字符是小寫字母的字符串匹配。

          前面曾經提到^表示字符串的開頭,但它還有另外一個含義。當在一組方括號里使用^是,它表示“非”或“排除”的意思,常常用來剔除某個字符。還用前面的例子,我們要求第一個字符不能是數字:

          ^[^0-9][0-9]$

          這個模式與”&5″、”g7″及”-2″是匹配的,但與”12″、”66″是不匹配的。下面是幾個排除特定字符的例子:

          [^a-z] //除了小寫字母以外的所有字符
          [^\\\/\^] //除了(\)(/)(^)之外的所有字符
          [^\"\'] //除了雙引號(")和單引號(')之外的所有字符

          特殊字符”.” (點,句號)在正規表達式中用來表示除了“新行”之外的所有字符。所以模式”^.5$”與任何兩個字符的、以數字5結尾和以其他非“新行”字符開頭的字符串匹配。模式”.”可以匹配任何字符串,除了空串和只包括一個“新行”的字符串。

          PHP的正規表達式有一些內置的通用字符簇,列表如下:

          字符簇 含義
          [[:alpha:]] 任何字母
          [[:digit:]] 任何數字
          [[:alnum:]] 任何字母和數字
          [[:space:]] 任何白字符
          [[:upper:]] 任何大寫字母
          [[:lower:]] 任何小寫字母
          [[:punct:]] 任何標點符號
          [[:xdigit:]] 任何16進制的數字,相當于[0-9a-fA-F]

          7.3 確定重復出現

          到現在為止,你已經知道如何去匹配一個字母或數字,但更多的情況下,可能要匹配一個單詞或一組數字。一個單詞有若干個字母組成,一組數字有若干個單數組成。跟在字符或字符簇后面的花括號({})用來確定前面的內容的重復出現的次數。

          字符簇 含義
          ^[a-zA-Z_]$ 所有的字母和下劃線
          ^[[:alpha:]]{3}$ 所有的3個字母的單詞
          ^a$ 字母a
          ^a{4}$ aaaa
          ^a{2,4}$ aa,aaa或aaaa
          ^a{1,3}$ a,aa或aaa
          ^a{2,}$ 包含多于兩個a的字符串
          ^a{2,} 如:aardvark和aaab,但apple不行
          a{2,} 如:baad和aaa,但Nantucket不行
          \t{2} 兩個制表符
          .{2} 所有的兩個字符

          這些例子描述了花括號的三種不同的用法。一個數字,{x}的意思是“前面的字符或字符簇只出現x次”;一個數字加逗號,{x,}的意思是“前面的內容出現x或更多的次數”;兩個用逗號分隔的數字,{x,y}表示“前面的內容至少出現x次,但不超過y次”。我們可以把模式擴展到更多的單詞或數字:

          ^[a-zA-Z0-9_]{1,}$ //所有包含一個以上的字母、數字或下劃線的字符串
          ^[0-9]{1,}$ //所有的正數
          ^\-{0,1}[0-9]{1,}$ //所有的整數
          ^\-{0,1}[0-9]{0,}\.{0,1}[0-9]{0,}$ //所有的小數

          最后一個例子不太好理解,是嗎?這么看吧:與所有以一個可選的負號(\-{0,1})開頭(^)、跟著0個或更多的數字([0-9]{0,})、和一個可選的小數點(\.{0,1})再跟上0個或多個數字([0-9]{0,}),并且沒有其他任何東西($)。下面你將知道能夠使用的更為簡單的方法。

          特殊字符”?”與{0,1}是相等的,它們都代表著:“0個或1個前面的內容”或“前面的內容是可選的”。所以剛才的例子可以簡化為:

          ^\-?[0-9]{0,}\.?[0-9]{0,}$

          特殊字符”*”與{0,}是相等的,它們都代表著“0個或多個前面的內容”。最后,字符”+”與 {1,}是相等的,表示“1個或多個前面的內容”,所以上面的4個例子可以寫成:

          ^[a-zA-Z0-9_]+$ //所有包含一個以上的字母、數字或下劃線的字符串
          ^[0-9]+$ //所有的正數
          ^\-?[0-9]+$ //所有的整數
          ^\-?[0-9]*\.?[0-9]*$ //所有的小數

          當然這并不能從技術上降低正規表達式的復雜性,但可以使它們更容易閱讀。

          posted @ 2006-10-14 21:59 xyang 閱讀(373) | 評論 (0)編輯 收藏

          • Liferay - Liferay is designed to deploy portlets that adhere to the Portlet API (JSR 168). Many useful portlets are bundled with the portal (Mail, Document Library, Calendar, Message Boards, to name a few) and can be used as examples for adding your own custom portlets.
          • Exo - The eXo platform is a powerful Open Source - JSR 168 compliant - enterprise portal built from several modules. Based on the most innovative tools, API and frameworks such as Java Server Faces, Pico Container, JbossMX and AspectJ.
          • Pluto - Pluto is the Reference Implementation of the Java Portlet Specfication. The current version of this specification is JSR 168.
          • JA-SIG uPortal - uPortal is a free, sharable portal under development by institutions of higher-education. Community tools, such as chat, forums, survey, and so on, build relationships among campus constituencies. uPortal is an open-standard effort using Java, XML, JSP and J2EE.
          • Redhat Portal Server - Red Hat Portal Server is a open source Portal solution. Supports multiple languages in its user interface and pervasive devices such as WAP, XHTML, and VoiceXML in its rendering pipeline. Portals can be built and targeted for the individual, for work groups or teams, for people with a common set of interests, and for large corporations and organizations.
          • Jakarta Jetspeed 2 Enterprise Portal - Jetspeed is an Open Source implementation of an Enterprise Information Portal, using Java and XML. etspeed-2 is the next-generation enterprise portal at Apache. Jetspeed-2 offers several architectural enhancements and improvements over Jetspeed 1.0. First, Jetspeed-2 is conformant to the Java Portlet Standard and will provide a standard mechanism for the deployment of portlets.
          • Jahia - An integrated web content management and corporate portal server; 100% Java based; Available under a collaborative source license (contribue or pay paradigm); Installed in minutes; Easy to use and to administer; Full Multilanguage and I18N support; Staging environement; Content Workflow; Content Versioning; Document Management (WebDAV Support); Built-in Portlet-based interface; Built-in support for standardized java web applications and web services (default servlets supported as portlets); Full web-based administration; Integrated with the Apache Lucene Search Engine; LDAP compliant; JSP and JSTL support for easy templates development; Integrated HTML cache engine; dynamic XML export module and much more...
          • Gluecode Portal Foundation Server - Gluecode PFS is built in collaboration with the largest open source communities, including JBoss and Apache. It adheres to J2EE specifications, as well as implementations of portal industry standards.
          • jPortlet - jPortlet is not JSR 168 compliant, but the jPortlet API is very similar to the IBM WebSpere Portal Server.
          • GridSphere - 100% JSR 168 Portlet API compliant. Portlet API implementation nearly fully compatible with IBM's WebSphere 4.2. Higher-level model for building complex portlets using visual beans and the GridSphere User Interface (UI) tag library. Built-in support for Role Based Access Control (RBAC) separating users into guests, users, admins and super users. Persistence of data provided using Hibernate for RDBMS database support Integrated Junit/Cactus unit tests. Localization support including English, French, German, Czech, Polish, Hungarian and Italian.
          • Cocoon Portal Framework - Apache Cocoon is a web development framework built around the concepts of separation of concerns and component-based web development. Cocoon implements these concepts around the notion of 'component pipelines', each component on the pipeline specializing on a particular operation. The Portal Framework is based on Cocoon and is rumored to eventually support JSR-168.
          • jPorta - jPorta is a fully functional portal engine built on top of the Jeenius Framework (http://jeenius.sourceforge.net). It works with any 2.3 compilant servlet engine and comes with a number of useful gadgets.
          • MyPersonalizer - MyPersonalizer is a J2EE-based framework. The controller layer is built upon Jakarta Struts. MyPersonalizer also provides a number of command line administration tools for initialization tasks and a web administration tool to administrate any portal built with the framework.
          • oPortal - The OWASP Portal project, oPortal, is a portal written in java that aims to become the standard for secure web applications. The OWASP portal is based on the Jakarta Struts framework and designed with security as a REQUIREMENT, not an option. A reference implementation of a secure portal, that will rival the likes of any commercially available portal. JSR-168 compliance scheduled for version 1.1 release.
          • CHEF - CompreHensive collaborativeE Framework. CHEF is a Java J2EE (Servlet) based application server. The portal engine is a version of Apache's Jetspeed. CHEF is a set of tools and services. Tools control an application's user interface. Services provide information modeling, persistence, and important application logic. The tools are a set of groupware applications (such as chat, schedule and resources). The services specifically support the tools (such as content hosting and messaging) and generally support the application environment (such as authentication, event tracking, security).
          • Siemens Intranet Portal Framework - The Siemens Intranet Portal Framework (SIPF) offers a personalized, structured access to information and seamless integration of applications. A web-based work environment is realized within a browser by hierarchically structured virtual desktops.
          • Lutece - Lutece is a web portal engine that lets you quickly create internet or intranet dynamic sites based on HTML, XML or database contents. This tool, developed by the Data Processing Department of the City of Paris for the districts web sites projects, is now used by more than 18 web sites of the city.
          • Sakai Project - Builds on JSR 168 and OKI open service interface definitions. A re-factored set of educational software tools that blends the best of features from the University of Michigan, Indiana University, MIT, Stanford, and the uPortal consortium. The Sakai Project will include an Enterprise Services-based Portal, a complete Course Management System with sophisticated assessment tools, a Research Support Collaboration System, a Workflow Engine, and a Technology Portability Profile as a clear standard for writing future tools that can extend this core set of educational applications. The Sakai Project Core universities are committing over $2 million per year to launch and support this two year project.
          • JBoss Portal - JBoss Portal 2.0 framework and architecture includes the portal container and supports a wide range of features including standard portlets, single sign-on, clustering and internationalization. Portal themes and layouts are configurable. Fine-grained security administration down to portlet permissions rounds out the security model. JBoss Portal 2.0 includes a rich content management system and message board support.
          • Stringbeans - Stringbeans is a platform for building enterprise information portals. The platform is composed of three components: a portal container/server, a Web Services framework, and a process automation engine. Compatible with JSR 168 standard, mobile client support (WML 1.1 and XHTML MP 1.0), JAAS-based user authentication, portlets capable of displaying RSS headlines, multi-page tabular data from database tables, reports, charts, XML documents via XSL tranformations. Stringbeans is deployed as a J2EE Web application in a container that supports Servlets 2.3 and Java Server Pages (JSP) 1.2 specification. EJB support is not required.
          • InfoGlue 2.0 - InfoGlue is a GPL-based content management and JSR 168 Portal system. Key features includes full multi-language support, excellent information reuse between sites and extensive integration capabilities. A dynamic visual page builder. This release supports advanced workflows as well as very detailed access control both internally and externally.
          • NodeVision Portal - NVPortal is the Java Enterprise JSR 168 compliant Portal solution based on a BSD-License. Features include a Business Process Engine and Search Engine based on SOAP, WSRP compliance, Multilingual, Single Sign On and a Graphical administration interface.
          • Pentaho - The Pentaho BI Project provides enterprise-class reporting, analysis, dashboard, data mining and workflow capabilities that help organizations operate more efficiently and effectively. The software offers flexible deployment options that enable use as embeddable components, customized BI application solutions, and as a complete out-of-the-box, integrated BI platform.
          • IPoint Open Edition - iPoint Open Edition has passed the JSR168 TCK. It is designed so that the portal can be developed within a browser. iPoint portal contains many prebuilt portlets and features complete browser based management and site construction.
          • Portals in Cocoon - The portal framework is a portal server that runs inside Cocoon - or to be more precise inside the Cocoon servlet. It contains a portlet container that is called coplet container. Coplet stands for Cocoon Portlet and is the Cocoon equivalent to portlet. The new portal engine is a replacement implementation of a portal engine which focuses on more flexibility and ease-of-use. In addition it supports the JSR-168.
          • Enterprise-class Portal Server Open Source project - The Portal Server open source project is derived from the Sun Java System Portal Server 7 product and will comprise of the following components and technologies: Portlet repository, JSR168 compliant portlet container, Web Services for Remote Portlets (WSRP) 1.0 based producer and consumer implementations, Portal aggregation and administration framework, Communities and collaboration framework/services, Full-text search engine with federated search and taxonomy capabilities, Secure remote access for SSL/VPN capabilities from outside the firewall and Multi-device mobile access capability to all portal content and applications.

          posted @ 2006-10-10 09:44 xyang 閱讀(667) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 陆良县| 铜梁县| 壶关县| 蒙城县| 台湾省| 衡水市| 磐石市| 普兰店市| 巫溪县| 南乐县| 金乡县| 惠东县| 徐闻县| 荆门市| 南通市| 称多县| 临澧县| 文安县| 成都市| 读书| 秦安县| 微山县| 澳门| 集安市| 姜堰市| 五河县| 清水河县| 娱乐| 盱眙县| 余庆县| 化德县| 龙口市| 宣威市| 江孜县| 宁夏| 鲁甸县| 化德县| 科尔| 乌鲁木齐市| 柘荣县| 颍上县|