wrapops

This module gathers text operations that are wrapped from standard python functions

WrapOp

class textops.WrapOp

WrapOpIter

class textops.WrapOpIter

WrapOpStr

class textops.WrapOpStr

resub

class textops.resub(string, count=0, flags=0)

Substitute a regular expression within a string or a list of strings

It uses re.sub() to replace the input text.

Parameters:
  • pattern (str) – Split string by the occurrences of pattern
  • repl (str) – Replacement string.
  • count (int) – the maximum number of pattern occurrences to be replaced
  • flags (int) – regular expression flags (re.I etc…). Only available in Python 2.7+
Returns:

The replaced text

Return type:

str or list

Examples

>>> 'Words, words, words.' | resub('[Ww]ords','Mots')
'Mots, Mots, Mots.'
>>> ['Words1 words2', 'words', 'words.' ] >> resub('[Ww]ords','Mots',1)
['Mots1 words2', 'Mots', 'Mots.']