LoginSignup
5
3

More than 5 years have passed since last update.

Haskellで日本語を正規表現で置換

Last updated at Posted at 2017-08-17

Haskell初心者。練習として、マークダウンのパーサーを作成中。

日本語の置換でかなりはまったが、 utf8-string パッケージでうにゃうにゃしたらいけた。

main.hs
import Text.Regex
import Codec.Binary.UTF8.String

sub :: String -> String -> String -> String
sub subject re replace = decodeString $ subRegex (mkRegex re) (encodeString subject) replace

main :: IO ()
main = do
    putStrLn $ sub "- Slackに通知する" "^- (.+)$" "<li>\\1</li>"
% runghc main.hs 
<li>Slackに通知する</li>             

encodeStringdecodeString で挟まないと、うまく置換できない。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3