Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

20
LINES

< > BotCompany Repo | #1005237 // regexReplace - with function callback or string replacement

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10794L/60K).

1  
// f : Matcher -> S
2  
sS regexReplace(S s, S pat, O f) {
3  
  ret regexReplace(regexpMatcher(pat, s), f);
4  
}
5  
6  
sS regexReplace(S s, S pat, S replacement) {
7  
  ret regexpReplace_direct(s, pat, replacement);
8  
}
9  
10  
sS regexReplace(Matcher m, O f) {
11  
  new StringBuffer buf;
12  
  while (m.find())
13  
    m.appendReplacement(buf, m.quoteReplacement(str(callF(f, m))));
14  
  m.appendTail(buf);
15  
  ret str(buf);
16  
}
17  
18  
sS regexReplace(S s, S pat, IF1<Matcher, S> f) {
19  
  ret regexReplace(s, pat, (O) f);
20  
}

Author comment

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/10
Text MD5: f61b3019966de7a581f6f7cc63a88fea
Transpilation MD5: 5ce87030482a00f3d01322e1e684e54c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2024-10-19 22:11:03
Source code size: 490 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 580 / 719
Version history: 9 change(s)
Referenced in: [show references]