Extract a number from a string, after a certain character
<p>Ayyyy, I need some help. I have the following strings, always in "char,num" format:</p>

<pre><code>s = "abcdef,12"
v = "gbhjjj,699"
</code></pre>

<p>I want to get just the digits after the comma, how do I do that without splitting the string with the comma as a delimiter?</p>

<p>I tried <code>s[-2:]</code> and <code>v[-3:]</code> which works, but how do I make it work without knowing the number of digits?</p>

<p>Using <code>split</code> is superior because it is very clear and fast:</p>

<pre><code>&gt;&gt;&gt; s = "abcdef,12"
&gt;&gt;&gt; s.split(',')[1]
'12'
</code></pre>

<p>Another way is with <code>index</code> or <code>find</code>:</p>

<pre><code>&gt;&gt;&gt; s = "abcdef,12"
&gt;&gt;&gt; s[s.find(',')+1:]
'12'
</code></pre>

<p>And another way with <code>re</code>:</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; s = "abcdef,12"
&gt;&gt;&gt; re.search(r',(.*)', s).group(1)
'12'
</code></pre>

<p>And with <code>csv</code> (and <code>io</code> so I don't have to write a file to the hard drive):</p>

<pre><code>&gt;&gt;&gt; import csv
&gt;&gt;&gt; import io
&gt;&gt;&gt; s = "abcdef,12"
&gt;&gt;&gt; r = csv.reader(i)
&gt;&gt;&gt; for line in r:
...     print(line[1])
...
12
</code></pre>

<p>I'm sure there are other ways to accomplish this task. This is just a small sample.</p>

python