文字列から、記述したパターンにマッチするもの全てを取得する関数 getMatchAll を作ってみた。
実行例: *Match> getMatchAll (string "ap") "apple juice, bad apple" Just ["ap","ap"] *Match> getMatchAll (do m <- string "a"; n <- count 1 anyChar; return (m++n)) "apple juice, bad apple" Just ["ap","ad","ap"] ソース: import Text.ParserCombinators.Parsec getMatchAll expr line = case parse getAllParser "" line of Left _ -> Nothing Right x -> Just x where get1Parser = try (expr) <|> do {anyChar; get1Parser} getAllParser = do n <- get1Parser m <- try (getAllParser) <|> do {many anyChar; return []} return ([n] ++ m)
by tnomura9
| 2011-12-01 13:16
| Haskell
|
Comments(0)
|
カテゴリ
新型コロナウイルス 主インデックス Haskell 記事リスト 圏論記事リスト 考えるということのリスト 考えるということ ラッセルのパラドックス Haskell Prelude Ocaml ボーカロイド 圏論 jQuery デモ HTML Python ツールボックス XAMPP Ruby ubuntu WordPress 脳の話 話のネタ リンク 幸福論 キリスト教 心の話 メモ 電子カルテ Dojo JavaScript C# NetWalker ed と sed HTML Raspberry Pi C 言語 命題論理 以前の記事
最新のトラックバック
最新のコメント
ファン
記事ランキング
ブログジャンル
画像一覧
|
ファン申請 |
||