We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

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.