<div dir="ltr">Really, you could also just use re.match:<div><br></div><div><br></div><div>import re</div><div><br></div><div>pat = re.compile(r'(\d\d):(\d\d):(\d\d),(\d{3}) --> (\d\d):(\d\d):(\d\d),(\d{3})')</div><div>def parse(string): return pat.match(string)</div><div><br></div><div>...</div><div><br></div><div>print(parse('<span style="font-size:12.8000001907349px">00:02:34,452 --> 00:02:37,927</span>')) # prints<span style="font-size:12.8000001907349px"> </span><span style="font-size:12.8000001907349px">['00', '02', '34', '452', '00', '02', '37', '927']</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><br></div><div><span style="font-size:12.8000001907349px">That way, if the input is invalid, `None` will be returned, so you have free error checking (sort of).</span></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 28, 2015 at 5:23 PM, Ryan Gonzalez <span dir="ltr"><<a href="mailto:rymg19@gmail.com" target="_blank">rymg19@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">import re<div>parts = re.split(':|(-->)|,', '00:02:34...')</div><div><br></div><div><div><br></div></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Mon, Sep 28, 2015 at 5:10 PM, Niilos <span dir="ltr"><<a href="mailto:niilos@gmx.com" target="_blank">niilos@gmx.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello everyone,<br>
<br>
I was wondering how to split a string with multiple separators.<br>
For instance, if I edit some subtitle file and I want the string '00:02:34,452 --> 00:02:37,927' to become ['00', '02', '34', '452', '00', '02', '37', '927'] I have to use split too much time and I didn't find a "clean" way to do it.<br>
I imagined the split function with an iterator as parameter. The string would be split each time its substring is in the iterator.<br>
<br>
Here is the syntax I considered for this :<br>
<br>
>>> '00:02:34,452 --> 00:02:37,927'.split([ ':', ' --> ', ',' ])<br>
['00', '02', '34', '452', '00', '02', '37', '927']<br>
<br>
Is it a relevant idea ? What do you think about it ?<br>
<br>
Regards,<br>
Niilos.<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Ryan</div><div dir="ltr">[ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.<br></div><div dir="ltr"><div><a href="http://kirbyfan64.github.io/" target="_blank">http://kirbyfan64.github.io/</a><div style="display:inline-block;width:16px;min-height:16px"> </div></div></div></div></div></div></div></div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Ryan</div><div dir="ltr">[ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.<br></div><div dir="ltr"><div><a href="http://kirbyfan64.github.io/" target="_blank">http://kirbyfan64.github.io/</a><div style="display:inline-block;width:16px;height:16px"> </div></div></div></div></div></div></div></div>
</div>