[Tutor] string delimiters
Peter Otten
__peter__ at web.de
Thu Jun 4 00:00:57 CEST 2015
richard kappler wrote:
> Perhaps the better way for me to have asked this question would have been:
>
> How can I find the location within a string of every instance of a
> character such as ']'?
>>> import re
>>> s = "alpha]beta]gamma]delta"
>>> [m.start() for m in re.finditer(r"]", s)]
[5, 10, 16]
But do you really need these locations? Why not just split() as in
>>> s.split("]")
['alpha', 'beta', 'gamma', 'delta']
More information about the Tutor
mailing list