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

16
LINES

< > BotCompany Repo | #1021192 // regexpReplaceWithFirstGroup - replace occurrence with first group of pattern

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

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

1  
sS regexpReplaceWithFirstGroup(Pattern pat, S s) {
2  
  ret regexpReplaceWithFirstGroup(regexp(pat, s));
3  
}
4  
5  
// TODO: why IC?
6  
sS regexpReplaceWithFirstGroup(S pat, S s) {
7  
  ret regexpReplaceWithFirstGroup(regexpIC(pat, s));
8  
}
9  
10  
sS regexpReplaceWithFirstGroup(Matcher m) {
11  
  new StringBuffer buf;
12  
  while (m.find())
13  
    m.appendReplacement(buf, m.group(1));
14  
  m.appendTail(buf);
15  
  ret str(buf);
16  
}

Author comment

Began life as a copy of #1018263

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1021192
Snippet name: regexpReplaceWithFirstGroup - replace occurrence with first group of pattern
Eternal ID of this version: #1021192/4
Text MD5: 143e33fe15802d28afe901be41625a8f
Transpilation MD5: 461ea1c52e02ba70fb064643f89d59ab
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-06-07 17:58:28
Source code size: 405 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 224 / 311
Version history: 3 change(s)
Referenced in: [show references]