I think you want something like this instead (note the lack of a dot after [a-zA-Z]
):
ur'^(?P<search_word>[a-zA-Z]*)/?$'
In your original regex, .*?
will allow for any character(s) (even spaces, for example). Also, [a-zA-Z]
will only match a single character unless it is followed by an *
or a +
.
Here is an example of my regex using the re
module:
>>> import re
>>> re.match(ur'^(?P<search_word>[a-zA-Z]*)/?$', 'testString/')
<_sre.SRE_Match object at 0x02BF4F20> # matches 'testString/'
>>> re.match(ur'^(?P<search_word>[a-zA-Z]*)/?$', 'test-String/') # does not match 'test-String/' because of the hyphen
>>> re.match(ur'^(?P<search_word>[a-zA-Z]*)/?$', '') # also matches empty string ''
<_sre.SRE_Match object at 0x02BF44A0>