Python RegEx in-text slash escape
<p>I apologize for the incoherent title, but it's hard to come up with one in this situation.</p>

<p>I have a bunch of texts and (almost) always they start either like this:</p>

<pre><code>Word (Foo) - Main Text
</code></pre>

<p>or this:</p>

<pre><code>Word (Foo/Bar) - Main Text
</code></pre>

<p>I want to remove everything before the <code>Main Text</code>, but it seems like the <code>/</code> character is messing up the regex I have.</p>

<p>So far I have this: <code>re.search('^[^)]*/*\)(.*)$', my_text)</code></p>

<p>I've tested it on the regex101 site, and it should work on both instances (either with or without the <code>/</code>) However, when I plug it in my Python code, it returns a <code>NoneType</code> when it encounters a <code>/</code>. What am I missing?</p>

<p>Do:</p>

<pre><code>^[^-]*-\s*(.*)
</code></pre>

<p>Now only captured group is your desired portion.</p>

<ul>
<li><p><code>^[^-]*</code> matches substring upto first <code>-</code></p></li>
<li><p><code>-</code> matches a literal <code>-</code>, <code>\s*</code> matches zero or more whitespace</p></li>
<li><p>The only captured group <code>(.*)</code> matches rest of the string</p></li>
</ul>

<p><strong>Example:</strong></p>

<pre><code>In [10]: s = 'Word (Foo/Bar) - Main Text'

In [11]: re.search(r'^[^-]*-\s*(.*)', s).group(1)
Out[11]: 'Main Text'
</code></pre>

python regex