Finding string in the format of TEXT-###, e.g SFS-444 inside of another string
<p>Pretty much as the statement states, I'm trying to figure out how to find text that follows this format TEXT-### inside of another string. However, there may be a lot of words or multiple numbers, such as,</p>

<pre><code>FRS-44215
SLMP-44
AG-1
</code></pre>

<p>So for example I have this text.</p>

<pre><code>"Lorem ipsum dolor sit amet, adversarium suscipiantur 
has ea, duo at alia assum, eu ius hinc 
aliquip percipitur SGF-7852 Nec ne 
nisl duis volutpat"
</code></pre>

<p>The code would pick out <code>SGF-7852</code></p>

<p>Use a regular expression to define the pattern that you are looking for, and then search the string for it.</p>

<pre><code>&gt;&gt;&gt; s = '''"Lorem ipsum dolor sit amet, adversarium suscipiantur 
... has ea, duo at alia assum, eu ius hinc 
... aliquip percipitur SGF-7852 Nec ne 
... nisl duis volutpat"'''
&gt;&gt;&gt; e = r'[A-Z]+-\d+'
&gt;&gt;&gt; import re
&gt;&gt;&gt; re.findall(e, s)
['SGF-7852']
</code></pre>

<p>Here the pattern is:</p>

<ul>
<li><code>[A-Z]+</code> (one or more capital letters)</li>
<li><code>-</code> followed by a dash</li>
<li><code>\d+</code> followed by one or more numbers</li>
</ul>

python string subset