mindspore.dataset.text.transforms.RegexReplace

class mindspore.dataset.text.transforms.RegexReplace(pattern, replace, replace_all=True)[source]

Replace UTF-8 string tensor with ‘replace’ according to regular expression ‘pattern’.

See http://userguide.icu-project.org/strings/regexp for support regex pattern.

Note

RegexReplace is not supported on Windows platform yet.

Parameters
  • pattern (str) – the regex expression patterns.

  • replace (str) – the string to replace matched element.

  • replace_all (bool, optional) – If False, only replace first matched element; if True, replace all matched elements (default=True).

Examples

>>> pattern = 'Canada'
>>> replace = 'China'
>>> replace_op = text.RegexReplace(pattern, replace)
>>> text_file_dataset = text_file_dataset.map(operations=replace_op)