Using anchors in python regex to get exact match
Question: I need to validate a version number consisting of 'v' plus positive int, and
nothing else eg "v4", "v1004"

I have

    
    
    import re
    pattern = "\Av(?=\d+)\W"
    
    m = re.match(pattern, "v303")
    if m is None:
        print "noMatch"
    else:
        print "match"
    

But this doesn't work! Removing the \A and \W will match for v303 but will
also match for v30G, for example

Thanks


Answer: Pretty straightforward. First, put anchors on your pattern:

    
    
    "^patternhere$"
    

Now, let's put together the pattern:

    
    
    "^v\d+$"
    

That should do it.

