replace_regex method

replace_regex(input_file_name, output_file_name, pattern, replacement)

Replaces all occurrences of a specified character string pattern with a replacement string in the input file using a regular expression.

def replace_regex(self, input_file_name: str, output_file_name: str, pattern: str, replacement: str):
    ...
ParameterTypeDescription
input_file_namestrThe input file name.
output_file_namestrThe output file name.
patternstrA regular expression pattern used to find matches.
replacementstrA string to replace all occurrences of pattern.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Returns

The number of replacements made.

replace_regex(input_file_name, output_file_name, save_format, pattern, replacement, options)

Replaces all occurrences of a specified character string pattern with a replacement string in the input file using a regular expression, with the specified save format and additional options.

def replace_regex(self, input_file_name: str, output_file_name: str, save_format: aspose.words.SaveFormat, pattern: str, replacement: str, options: aspose.words.replacing.FindReplaceOptions):
    ...
ParameterTypeDescription
input_file_namestrThe input file name.
output_file_namestrThe output file name.
save_formatSaveFormatThe save format.
patternstrA regular expression pattern used to find matches.
replacementstrA string to replace all occurrences of pattern.
optionsFindReplaceOptionsFindReplaceOptions object to specify additional options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Returns

The number of replacements made.

replace_regex(input_file_name, output_file_name, save_options, pattern, replacement, options)

Replaces all occurrences of a specified character string pattern with a replacement string in the input file using a regular expression, with the specified save format and additional options.

def replace_regex(self, input_file_name: str, output_file_name: str, save_options: aspose.words.saving.SaveOptions, pattern: str, replacement: str, options: aspose.words.replacing.FindReplaceOptions):
    ...
ParameterTypeDescription
input_file_namestrThe input file name.
output_file_namestrThe output file name.
save_optionsSaveOptionsThe save options.
patternstrA regular expression pattern used to find matches.
replacementstrA string to replace all occurrences of pattern.
optionsFindReplaceOptionsFindReplaceOptions object to specify additional options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Returns

The number of replacements made.

replace_regex(input_stream, output_stream, save_format, pattern, replacement, options)

Replaces all occurrences of a specified character string pattern with a replacement string in the input stream using a regular expression, with the specified save format and additional options.

def replace_regex(self, input_stream: io.BytesIO, output_stream: io.BytesIO, save_format: aspose.words.SaveFormat, pattern: str, replacement: str, options: aspose.words.replacing.FindReplaceOptions):
    ...
ParameterTypeDescription
input_streamio.BytesIOThe input stream.
output_streamio.BytesIOThe output stream.
save_formatSaveFormatThe save format.
patternstrA regular expression pattern used to find matches.
replacementstrA string to replace all occurrences of pattern.
optionsFindReplaceOptionsFindReplaceOptions object to specify additional options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.

Returns

The number of replacements made.

replace_regex(input_stream, output_stream, save_options, pattern, replacement, options)

Replaces all occurrences of a specified character string pattern with a replacement string in the input stream using a regular expression, with the specified save format and additional options.

def replace_regex(self, input_stream: io.BytesIO, output_stream: io.BytesIO, save_options: aspose.words.saving.SaveOptions, pattern: str, replacement: str, options: aspose.words.replacing.FindReplaceOptions):
    ...
ParameterTypeDescription
input_streamio.BytesIOThe input stream.
output_streamio.BytesIOThe output stream.
save_optionsSaveOptionsThe save options.
patternstrA regular expression pattern used to find matches.
replacementstrA string to replace all occurrences of pattern.
optionsFindReplaceOptionsFindReplaceOptions object to specify additional options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.

Returns

The number of replacements made.

See Also