Cutting slices

Christian Gollwitzer auriocus at gmx.de
Mon Mar 6 03:07:32 EST 2023


Am 05.03.23 um 23:43 schrieb Stefan Ram:
>    The following behaviour of Python strikes me as being a bit
>    "irregular". A user tries to chop of sections from a string,
>    but does not use "split" because the separator might become
>    more complicated so that a regular expression will be required
>    to find it. 

OK, so if you want to use an RE for splitting, can you not use 
re.split() ? It basically works like the built-in splitting in AWK

 >>> s='alphaAbetaBgamma'
 >>> import re
 >>> re.split(r'A|B|C', s)
['alpha', 'beta', 'gamma']
 >>>


	Christian


More information about the Python-list mailing list