letpat="(foo[a-z]*bar|quxx)""A match with foodiabar after"=~pat::Bool--True"no match"=~pat::Bool-- False
返回第一个匹配的子串或者空串:
123
letpat="(foo[a-z]*bar|quxx)""A match with foodiabar after"=~pat::String--get "foodiabar""no match"=~pat::String-- get empty string
返回匹配的上下文信息:
12345
letpat="(foo[a-z]*bar|quxx)""A match with foodiabar after"=~pat::(String,String,String)-- get ("A match with ", "foodiabar", " after")"no match"=~pat::String-- get ("no match", "", "")
这里可以区分出是否有空串匹配。
4. 返回更多信息:
12345
letpat="(foo[a-z]*bar|quxx)""A match with foodiabar quxx after"=~pat::(String,String,String,[String])-- get ("A match with ", "foodiabar", " quxx after", ["foodiabar"])"no match"=~pat::(String,String,String,[String])-- get ("no match", "", "", [])