Delete all characters after a backslash in python?
<p>I have a for loop that changes the string current_part.
Current_part should have a format of 1234 but sometimes it has the format of 1234/gg</p>

<p>Other formats exist but in all of them, anything after the backlash need to be deleted.</p>

<p>I found a similar example below so I tried it but it didn't work. How can I fix this? Thanks</p>

<p><code>current_part =  re.sub(r"\B\\\w+", "", str(current_part))</code></p>

<p>You can split your string using <code>string.split()</code></p>

<p>for example:</p>

<pre><code>new_string = current_part.split("/")[0]
</code></pre>

python