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

19
LINES

< > BotCompany Repo | #1000470 // "bla" as ".+" with outPattern (learner)

JavaX fragment (include)

static class LBla extends LearnerImpl {
  static boolean debug;
  String inPattern, outPattern;

  public void processInOut(Object _in, Object _out) {
    String in = (String) _in, out = (String) _out;
    int i = in.indexOf("bla"), j = out.indexOf("bla");
    if (i < 0 || j < 0) fail();
    inPattern = "^" + patternQuote(in.substring(0, i))
      + "(.+)" + patternQuote(in.substring(i+3)) + "$";
    outPattern = Matcher.quoteReplacement(out.substring(0, j))
      + "$1" + Matcher.quoteReplacement(out.substring(j+3));
  }
  
  public Object processIn(Object _in) {
    String in = (String) _in;
    return in.replaceAll(inPattern, outPattern);
  }
}

Author comment

Began life as a copy of #1000468

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000470
Snippet name: "bla" as ".+" with outPattern (learner)
Eternal ID of this version: #1000470/1
Text MD5: 3fafde567ae4a19b3ff5b7d9e9371b94
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-09 16:35:51
Source code size: 673 bytes / 19 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 722 / 1886
Referenced in: [show references]