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 RegexRedaction.
init Initializes a new RegexRedaction.

Methods

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

Properties

Property Description
description The description of the redaction, containing its name and parameters.
regular_expression The regular expression used for matching.
action_options The ReplacementOptions instance specifying the type of text replacement. (inherited from TextRedaction)
ocr_connector The OCR connector 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.redaction.options.drawing import Color

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

Guides

Task guides that use RegexRedaction:

See Also