Regular express"" 代表 "or"
ex:2131 match "213 317 2316 31" 幾次?
match 4 次
[]代表任何一個在bracket裡的單一字元(single character). 代表任何單一字元- 代表範圍 Ex:[1-4] == [1234]
Ex:[1-3].[34] match "213 317 2316 31" 幾次? 解釋:第一個字元從1-3任何一個字元, 第二個字元是任何字元 第三個字元是3 or 4 字元match "213" and "3 3" 一共兩次
^ Match 開始的字元$ Match 最後的字元_ Match 控制字元 (逗點/空白/tab等)
Ex: ^21,31$,_31_ match "213 317 218 31 731" 幾次?^21 一次31$ 一次_31_ 一次(只match 31)
() parentheses 群組Ex:(213218)_31 match "213 317 1218 31 31"幾次?213 31218 31一共兩次
\ 用來移除特殊字元
Ex:^\(213_ 代表開頭從(213開始,因為(是特殊字元若要match (213 必須要把(當作一般字元,\之後接的特殊字元可以視為一般字元Ex: AS path 為 (213 317) 1218 316 31 若用^\(213_ 來match可以match出(213
* match 0個或多個前置字元 Ex: 1* 代表任何1的字串 (包含沒有任何字元) 1 or 11 or 111 etc..)) ? match 0個或1個前置字元 Ex: 1? 代表1 or 沒有任何字元
+ match 1個或多個前置字元 Ex: 1+ 代表任何1的字串 1 or 11 or 111 etc..))
練習:
_100_ Going through AS
100^100$ Directly connected to AS
100_100$ Originated in AS
100^100_. Networks behind AS 100
^[0-9]+$ AS paths one AS long
^([0-9]+)(_\1)*$ Prepending performed in neighboring originating AS
^$ Networks originated in local AS.* Matches everything
^([0-9]+)(_\1)*$ 比較難解釋,這個會match到相鄰的AS,以及相鄰且有做prepend的 AS
^([0-9]+)代表AS path只有一個的,也就是相鄰ASThe variable
“\1” is put into parentheses for the purpose of the multiplier operator“*”, meaning that this part can match any number of successive occurrences of the sameAS number that was matched by the “[0-9]+” expression. For example, this regularexpression matches AS paths “99 99 99”, “200”, “101 101”, or “5 5 5 5 5”, but it does notmatch the AS path “101 99”.
沒有留言:
張貼留言