My regex works on regex101 but doesn't work in python?
<p>So I need to match strings that are surrounded by <code>|</code>. So, the pattern should simply be <code>r"\|([^\|]*)\|"</code>, right? And yet:</p>

<pre><code>&gt;&gt;&gt; pattern = r"\|([^\|]*)\|"
&gt;&gt;&gt; re.match(pattern, "|test|")
&lt;_sre.SRE_Match object at 0x10341dd50&gt;
&gt;&gt;&gt; re.match(pattern, "  |test|")
&gt;&gt;&gt; re.match(pattern, "asdf|test|")
&gt;&gt;&gt; re.match(pattern, "asdf|test|1234")
&gt;&gt;&gt; re.match(pattern, "|test|1234")
&lt;_sre.SRE_Match object at 0x10341df30&gt;
</code></pre>

<p>It's only matching on strings that begin with <code>|</code>? It works just fine on regex101 and this is python 2.7 if it matters. I'm probably just doing something dumb here so any help would be appreciated. Thanks!</p>