Remove uuid4 string pattern
<p>I have the below string examples</p>

<pre><code>1# 00000 Gin-a19ea68e-64bf-4471-b4d1-44f6bd9c1708-62fa6ae2-599c-4ff1-8249-bf6411ce3be7-83930e63-2149-40f0-b6ff-0838596a9b89 Kin

2# 00000 Gin-a19ea68e-64bf-4471-b4d1-44f6bd9c1708 Kin
</code></pre>

<p>I am trying to remove the uuid4 generated string and any text that comes to the right of uuid4 string pattern in python.</p>

<p>The output should be <code>00000 Gin</code> in both the examples</p>

<p>I have checked here <a href="http://stackoverflow.com/questions/11384589/what-is-the-correct-regex-for-matching-values-generated-by-uuid-uuid4-hex">What is the correct regex for matching values generated by uuid.uuid4().hex?</a>. But still doesnt help.</p>

<p>You could use:</p>

<pre><code>import re

strings = ["00000 Gin-a19ea68e-64bf-4471-b4d1-44f6bd9c1708-62fa6ae2-599c-4ff1-8249-bf6411ce3be7-83930e63-2149-40f0-b6ff-0838596a9b89 Kin",
"00000 Gin-a19ea68e-64bf-4471-b4d1-44f6bd9c1708 Kin"]

rx = re.compile(r'^[^-]+')
# match the start and anything not - greedily

new_strings = [match.group(0)
                for string in strings
                for match in [rx.search(string)]
                if match]
print(new_strings)
# ['00000 Gin', '00000 Gin']
</code></pre>

<p><hr>
See <a href="http://ideone.com/c6MxV1" rel="nofollow"><strong>a demo on ideone.com</strong></a>.
<hr>
To actually <strong><em>check</em></strong> if your string is of the desired format, you could use the following expression:</p>

<pre><code>^
(?P&lt;interesting&gt;.+?)                   # before
(?P&lt;uid&gt;\b\w{8}-(?:\w{4}-){3}\w{12}\b) # uid
(?P&lt;junk&gt;.+)                           # garbage
$
</code></pre>

<p>See a demo for this one on <a href="https://regex101.com/r/uM0cA0/2" rel="nofollow"><strong>regex101.com</strong></a> (mind the modifiers!).</p>

python uuid