Skip to content

Commit 49f98a2

Browse files
mfikesdnolen
authored and
dnolen
committed
CLJS-2437: Update docstrings for str/replace and str/replace-first from Clojure
1 parent 6362dd0 commit 49f98a2

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/main/cljs/clojure/string.cljs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,24 @@
4343

4444
(defn replace
4545
"Replaces all instance of match with replacement in s.
46+
4647
match/replacement can be:
4748
4849
string / string
49-
pattern / (string or function of match)."
50+
pattern / (string or function of match).
51+
52+
See also replace-first.
53+
54+
The replacement is literal (i.e. none of its characters are treated
55+
specially) for all cases above except pattern / string.
56+
57+
For pattern / string, $1, $2, etc. in the replacement string are
58+
substituted with the string that matched the corresponding
59+
parenthesized group in the pattern.
60+
61+
Example:
62+
(clojure.string/replace \"Almost Pig Latin\" #\"\\b(\\w)(\\w+)\\b\" \"$2$1ay\")
63+
-> \"lmostAay igPay atinLay\""
5064
[s match replacement]
5165
(cond
5266
(string? match)
@@ -61,10 +75,25 @@
6175

6276
(defn replace-first
6377
"Replaces the first instance of match with replacement in s.
78+
6479
match/replacement can be:
6580
6681
string / string
67-
pattern / (string or function of match)."
82+
pattern / (string or function of match).
83+
84+
See also replace.
85+
86+
The replacement is literal (i.e. none of its characters are treated
87+
specially) for all cases above except pattern / string.
88+
89+
For pattern / string, $1, $2, etc. in the replacement string are
90+
substituted with the string that matched the corresponding
91+
parenthesized group in the pattern.
92+
93+
Example:
94+
(clojure.string/replace-first \"swap first two words\"
95+
#\"(\\w+)(\\s+)(\\w+)\" \"$3$2$1\")
96+
-> \"first swap two words\""
6897
[s match replacement]
6998
(.replace s match replacement))
7099

0 commit comments

Comments
 (0)