FindReplaceOptions constructor

FindReplaceOptions()

Initializes a new instance of the FindReplaceOptions class with default settings.

def __init__(self):
    ...

FindReplaceOptions(direction)

Initializes a new instance of the FindReplaceOptions class with the specified direction.

def __init__(self, direction: aspose.words.replacing.FindReplaceDirection):
    ...
ParameterTypeDescription
directionFindReplaceDirectionThe direction of the find and replace operation.

FindReplaceOptions(replacing_callback)

Initializes a new instance of the FindReplaceOptions class with the specified replacing callback.

def __init__(self, replacing_callback: aspose.words.replacing.IReplacingCallback):
    ...
ParameterTypeDescription
replacing_callbackIReplacingCallbackThe callback to use for replacing found text.

FindReplaceOptions(direction, replacing_callback)

Initializes a new instance of the FindReplaceOptions class with the specified direction and replacing callback.

def __init__(self, direction: aspose.words.replacing.FindReplaceDirection, replacing_callback: aspose.words.replacing.IReplacingCallback):
    ...
ParameterTypeDescription
directionFindReplaceDirectionThe direction of the find and replace operation.
replacing_callbackIReplacingCallbackThe callback to use for replacing found text.

Examples

Shows how to recognize and use substitutions within replacement patterns.

doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
builder.write('Jason gave money to Paul.')
regex = '([A-z]+) gave money to ([A-z]+)'
options = aw.replacing.FindReplaceOptions()
options.use_substitutions = True
# Using legacy mode does not support many advanced features, so we need to set it to 'false'.
options.legacy_mode = False
doc.range.replace_regex(pattern=regex, replacement='$2 took money from $1', options=options)
self.assertEqual(doc.get_text(), 'Paul took money from Jason.\x0c')

See Also