pattern.match with regex not working
<pre><code>import re

def test(stest):
    pattern = re.compile(r'/product\/(.*?)/i')

    result = pattern.match(stest)
    if result:
       print result.group()
    else:
       print "Doesn't match"

test('product/WKSGGPC104/GGPC-The-Paladin')
</code></pre>

<p>When I run the coding as the above, I will get "Doesn't match" for the result instead of 'product/'.</p>

<p>Could someone help me out? I have tested regular expression by using the online tool, it shows fine and matches the string that I am going to test. </p>

<p>Thank you for your help.</p>

<p>A couple of issues with your code.<br>
First, there was no <code>/</code> in the beginning, second, you provide the modifiers <strong>after</strong> the call:</p>

<pre><code>import re

def test(stest):
    pattern = re.compile(r'product/([^/]+)'. re.IGNORECASE)

    result = pattern.match(stest)
    if result:
       print(result.group())
    else:
       print("Doesn't match")

test('product/WKSGGPC104/GGPC-The-Paladin')
</code></pre>

<p>See <a href="http://ideone.com/TBgQMN" rel="nofollow"><strong>a demo on regex101.com</strong></a>.</p>

python regex