regex - unexpected end of regular expression in python -
hello learning web development in came across kind of error, regex code :
def valid_username(self , username): user_re = re.compile(r"^[a-za-z0-9_-]{3,20}$") if user_re.match(username): return username def valid_password(self, password): pass_re = re.compile(r"^.{3,20}$") if pass_re.match(password) : return password def valid_email(self, email): email_re = re.compile(r"^[\s]+@[\s]+\.[\s\+$") if email_re.match(email): return email
and error log:
traceback (most recent call last): file "/home/suraj/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__ rv = self.handle_exception(request, response, e) file "/home/suraj/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__ rv = self.router.dispatch(request, response) file "/home/suraj/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher return route.handler_adapter(request, response) file "/home/suraj/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__ return handler.dispatch() file "/home/suraj/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch return self.handle_exception(e, self.app.debug) file "/home/suraj/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch return method(*args, **kwargs) file "/home/suraj/google_apps/greetings/greetings.py", line 118, in post valid_email = self.valid_email(email) file "/home/suraj/google_apps/greetings/greetings.py", line 91, in valid_email email_re = re.compile(r"^[\s]+@[\s]+\.[\s\+$") file "/usr/lib/python2.7/re.py", line 190, in compile return _compile(pattern, flags) `file "/usr/lib/python2.7/re.py", line 244, in _compile raise error, v # invalid expression
error: unexpected end of regular expression
help nedded!thanks in advance
you failed put closing ]
bracket in email_re = re.compile(r"^[\s]+@[\s]+\.[\s\+$")
regex.
re.compile(r"^[\s]+@[\s]+\.[\s]+$")
you don't need character class.
re.compile(r"^\s+@\s+\.\s+$")
\s+
matches 1 or more non-space characters.
Comments
Post a Comment