RegexRedaction class

RegexRedaction class

Represents a text redaction that searches and replaces text in the document by matching provided regular expression.

Learn more

The RegexRedaction type exposes the following members:

Constructors

Constructor Description
init Initializes a new instance of RegexRedaction.
init Initializes a new RegexRedaction instance.

Methods

Method Description
apply_to Applies the redaction to a given format instance.
apply_to_document_format_instance

Properties

Property Description
description The description of the redaction, containing its name and parameters.
regular_expression The regular expression pattern used for matching.
action_options The ReplacementOptions instance specifying the type of text replacement. (inherited from TextRedaction)
ocr_connector The IOcrConnector implementation used to extract text from graphic content. (inherited from TextRedaction)

Example

from groupdocs.redaction import Redactor
from groupdocs.redaction.redactions import RegexRedaction, ReplacementOptions
from groupdocs.pydrawing import Color

with Redactor("sample.pdf") as redactor:
    # replace with text
    redactor.apply(RegexRedaction(r"\d{2}\s*\d{2}[^\d]*\d{6}", ReplacementOptions("[removed]")))
    # replace with blue solid rectangle
    redactor.apply(RegexRedaction(r"^\d+[,\.]{1}\d+$", ReplacementOptions(Color.BLUE)))
    redactor.save()

Guides

Task guides that use RegexRedaction:

See Also