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).

// f : Matcher -> S
sS regexReplace(S s, S pat, O f) {
  ret regexReplace(regexpMatcher(pat, s), f);
}

sS regexReplace(S s, S pat, S replacement) {
  ret regexpReplace_direct(s, pat, replacement);
}

sS regexReplace(Matcher m, O f) {
  new StringBuffer buf;
  while (m.find())
    m.appendReplacement(buf, m.quoteReplacement(str(callF(f, m))));
  m.appendTail(buf);
  ret str(buf);
}

sS regexReplace(S s, S pat, IF1<Matcher, S> f) {
  ret regexReplace(s, pat, (O) f);
}

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: 578 / 716
Version history: 9 change(s)
Referenced in: [show references]