Libraryless. Click here for Pure Java version (2862L/17K).
1 | // f : Matcher -> S |
2 | sS regexReplace(S s, S pat, O f) { |
3 | Matcher m = Pattern.compile(pat).matcher(s); |
4 | ret regexReplace(m, f); |
5 | } |
6 | |
7 | sS regexReplace(S s, S pat, S replacement) { |
8 | ret regexpReplace_direct(s, pat, replacement); |
9 | } |
10 | |
11 | sS regexReplace(Matcher m, O f) { |
12 | new StringBuffer buf; |
13 | while (m.find()) |
14 | m.appendReplacement(buf, m.quoteReplacement(str(callF(f, m)))); |
15 | m.appendTail(buf); |
16 | ret str(buf); |
17 | } |
18 | |
19 | sS regexReplace(S s, S pat, IF1<Matcher, S> f) { |
20 | ret regexReplace(s, pat, (O) f); |
21 | } |
Began life as a copy of #1005236
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005237 |
Snippet name: | regexReplace - with function callback or string replacement |
Eternal ID of this version: | #1005237/9 |
Text MD5: | 47c755dfb64daa4faa3b8a7cd2f74f15 |
Transpilation MD5: | 7596854f3df4dacc3a759683d0d503c3 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-05-29 21:38:22 |
Source code size: | 518 bytes / 21 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 497 / 598 |
Version history: | 8 change(s) |
Referenced in: | [show references] |