輸入:
pattern : 含有通配符*與?的字符串
string : 被匹配的字符串
輸出:true與false代表匹配成功與失敗
1 func match :: (list char) -> (list char) -> bool
2 def match pattern string =
3 select pattern of
4 case empty :
5 select string of
6 case empty : true
7 else : false
8 end
9 case list charp tailp :
10 select string of
11 case empty : and (equ charp '*') (match tailp empty)
12 case list chars tails :
13 select charp of
14 case '?' : match tailp tails
15 case '*' : or (match tailp tails) (match pattern tails)
16 else : and (equ charp chars) (match tailp tails)
17 end
18 end
19 end
posted on 2008-10-01 09:41
陳梓瀚(vczh) 閱讀(1471)
評論(0) 編輯 收藏 引用 所屬分類:
腳本技術