Skip to content

Multiple replacements with peg/match #1422

Answered by ianthehenry
MaxGyver83 asked this question in Q&A
Discussion options

You must be logged in to vote

1 matches the byte, but doesn't capture it. You can use:

(defn replace-utf8-peg [str]
  (peg/match ~(accumulate (any (+
                     (/ "=C3=A4" "ä")
                     (/ "=C3=B6" "ö")
                     (/ "=C3=BC" "ü")
                     '1)))
             str))

To do what you want (accumulate will join all the captured characters into a string efficiently, instead of giving you an array of characters at the end).

peg/replace is probably a better fit here, though. And assuming that you want to produce utf-8 encoded strings in your final result (which I guess is ambiguous given the code you provided -- I don't know your file encoding), you can just parse the bytes and don'…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MaxGyver83
Comment options

Answer selected by MaxGyver83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants