Generator method to split a string using the given expression as a separator. May be called with optional C{maxsplit} argument, to limit the number of splits; and the optional C{includeSeparators} argument (default=C{False}), if the separating matching text should be
(self, instring, maxsplit=_MAX_INT, includeSeparators=False)
| 1779 | raise exc |
| 1780 | |
| 1781 | def split(self, instring, maxsplit=_MAX_INT, includeSeparators=False): |
| 1782 | """ |
| 1783 | Generator method to split a string using the given expression as a separator. |
| 1784 | May be called with optional C{maxsplit} argument, to limit the number of splits; |
| 1785 | and the optional C{includeSeparators} argument (default=C{False}), if the separating |
| 1786 | matching text should be included in the split results. |
| 1787 | |
| 1788 | Example:: |
| 1789 | punc = oneOf(list(".,;:/-!?")) |
| 1790 | print(list(punc.split("This, this?, this sentence, is badly punctuated!"))) |
| 1791 | prints:: |
| 1792 | ['This', ' this', '', ' this sentence', ' is badly punctuated', ''] |
| 1793 | """ |
| 1794 | splits = 0 |
| 1795 | last = 0 |
| 1796 | for t,s,e in self.scanString(instring, maxMatches=maxsplit): |
| 1797 | yield instring[last:s] |
| 1798 | if includeSeparators: |
| 1799 | yield t[0] |
| 1800 | last = e |
| 1801 | yield instring[last:] |
| 1802 | |
| 1803 | def __add__(self, other ): |
| 1804 | """ |