Set replacement text in IRedactionCallback

I want to change original text with replacement text using RegexRedaction where I need to decide replacement text based on original text as well after matched by pattern. I am looking for something like below.

IRedactionCallback ip = e -> {
          if(e.getOriginalText().startsWith("99")) {
              e.getReplacement().setReplacement("[override]");
          }
          return true;
  };
Redactor redactor = new Redactor(indoc, loadOptions, new RedactorSettings(ip);
RegexRedaction r = new RegexRedaction("\d+{4}", new ReplacementOptions("[default value]"));
1 Like

@shiva.k

In general, you need as many text redactions (e.g. regular expressions) as many replacements you have. For your scenario, the following approach will work:

Redaction []redactions = new Redaction[] {
    new ExactPhraseRedaction("9999", new ReplacementOptions("[override]")),  
    new RegexRedaction("\\d{4}", new ReplacementOptions("[default]")),
};
RedactorChangeLog result = redactor.apply(redactions); 

Please note that in this case order is important, the first approach (ExactPhraseRedaction) applies first.

Hi @Atir_Tahir, my requirement is to do some complex operations like making API call and using the response of it to replace original text. In my case I can’t use static strings as replacement option, I need to get replacement text dynamically. Is there any extension point for that?

@shiva.k

There is no option to change the replacement value in process of redaction. However, if you share a detailed overview of your use-case or business logic, we may offer a workaround.

Hi I know its a very old post but I still working with groupdocs and this requirement came up again. Below is my use-case and please suggest if its possible in groupdocs redaction library.

I have office documents which I have to redact but replace original text with encrypted as replacement value.
I use regex based redaction and currently I can get the actual text that is matched but can’t encrypt that text and set as replacement value. Is there a way to achieve it.

Gracias,

@shiva.k
Thanks for the details. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): REDACTIONJAVA-187

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.