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

21
LINES

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

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

Libraryless. Click here for Pure Java version (2862L/17K).

// f : Matcher -> S
sS regexReplace(S s, S pat, O f) {
  Matcher m = Pattern.compile(pat).matcher(s);
  ret regexReplace(m, 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/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: 491 / 587
Version history: 8 change(s)
Referenced in: [show references]