replace函数用于用新的字符串值更换字符串中的子字符串
(replace str pat replacestr)
参数 - “ pat”是正则表达式模式, “ str”是需要根据模式在其中找到文本的字符串, “replacestr”是需要根据模式在原始字符串中替换的字符串。
(ns clojure.examples.example (:gen-class)) ;; This program displays Hello Learnfk (defn Example [] (def pat (re-pattern "\\d+")) (def newstr (clojure.string/replace"abc123de" pat "789")) (println newstr)) (Example)
上面的程序产生以下输出。
链接:https://www.learnfk.comhttps://www.learnfk.com/clojure/clojure-regular-expressions-replace.html
来源:LearnFk无涯教程网
abc789de
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)