regex - How to convert a string with french accents to an URL (replacing accent letters)? -
i want create urls based on strings automatically convert string french accents url.
(defn str->url [] ...) (defn str->url-case [] ...) (str->url "Élise noël") ;=> "/elise-noel" (str->url-case "Élise noël") ;=> "/elise-noel"
here non accent letters equivalents :
À,  -> Æ -> ae Ç -> c É, È, Ê, Ë -> e Î, Ï -> Ô -> o Œ -> oe Ù, Û, Ü -> u Ÿ -> y à, â -> æ -> ae ç -> c é, è, ê, ë -> e î, ï -> ô -> o œ -> oe ù, û, ü -> u ÿ -> y
thank you!
to use official url encoding format (application/x-www-form-urlencoded
), different removing accents, can this:
user> (java.net.urlencoder/encode "Élise noël" "utf-8") "%c3%89lise+no%c3%abl"
to use replacements question, map clojure.string/replace
each of replacement pairs on string.
here's example necessary replacement pairs example string. follow same pattern rest:
(reduce (fn [s [pat repl]] (clojure.string/replace s pat repl)) "Élise noël" [[" " "-"] [#"[ÉÈÊË]" "e"] [#"[éèêë]" "e"]])
Comments
Post a Comment