Text operation utils

moulinette.utils.text.search(pattern, text, count=0, flags=0)[source]

Search for pattern in a text

Scan through text looking for all locations where the regular expression pattern matches, and return them as a list of strings.

The optional argument count is the maximum number of pattern occurences to return; count must be an integer. If omitted or zero, all occurences will be returned. If it’s a negative number, occurences to return will be counted backward. If only one occurence is requested, it will be returned as a string.

The expression’s behaviour can be modified by specifying a flags value. Refer to the re module documentation for available variables.

moulinette.utils.text.searchf(pattern, path, count=0, flags=8)[source]

Search for pattern in a file

Map the file with given path to memory and search for pattern in it content by using the search function.

moulinette.utils.text.prependlines(text, prepend)[source]

Prepend a string to each line of a text

moulinette.utils.text.random_ascii(length=20)[source]

Return a random ascii string