mindspore.dataset.text.RegexReplace

View Source On Gitee
class mindspore.dataset.text.RegexReplace(pattern, replace, replace_all=True)[source]

Replace part of the input UTF-8 string with a difference text string using regular expressions.

Note

RegexReplace is not supported on Windows platform yet.

Parameters
  • pattern (str) – The regular expression, used to mean the specific, standard textual syntax for representing patterns for matching text.

  • replace (str) – The string used to replace the matched elements.

  • replace_all (bool, optional) – Whether to replace all matched elements. If False, only the first matched element will be replaced; otherwise, all matched elements will be replaced. Default: True.

Raises
  • TypeError – If pattern is not of type str.

  • TypeError – If replace is not of type str.

  • TypeError – If replace_all is not of type bool.

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.text as text
>>>
>>> regex_replace = text.RegexReplace('apple', 'orange')
>>> text_file_list = ["/path/to/text_file_dataset_file"]
>>> text_file_dataset = ds.TextFileDataset(dataset_files=text_file_list)
>>> text_file_dataset = text_file_dataset.map(operations=regex_replace)
Tutorial Examples: