substr

substr(x, start=0, end=None)

Get a substring of text from position start up to and including position end.

Parameters

Name Type Description Default
x Union[str, List[str]] A str or a list of str required
start Union[int, List[int]] The start position. Positions start at 0. 0
end Union[int, List[int]] The end position. The end position is inclusive. If None, the end position is taken as the maximum length of the string. None

Returns

Name Type Description
Union[str, List[str]] a substring of x or a list of these

Examples

>>> from rlike import *
>>> substr('Hello World', start = 0, end = 1)
'He'
>>> substr('Hello World', start = 1, end = 2)
'el'
>>> substr('Hello World', start = 6)
'World'
>>> substr('Hello World', start = [0, 3], end = [0+4, 3+2])
['Hello', 'lo ']
>>> substr(['Hello World', 'How are you?'], start = 0, end = 5)
['Hello ', 'How ar']
>>> substr(['Hello World', 'How are you?'], start = 0, end = [4, 6])
['Hello', 'How are']