Python 3.4 adds re.fullmatch()
Posted
by Jan Goyvaerts
on Regular-Expressions.info
See other posts from Regular-Expressions.info
or by Jan Goyvaerts
Published on Mon, 19 May 2014 06:56:05 +0000
Indexed on
2014/05/26
21:28 UTC
Read the original article
Hit count: 526
Uncategorized
Python 3.4 does not bring any changes to its regular expression syntax compared to previous 3.x releases. It does add one new function to the re module called fullmatch(). This function takes a regular expression and a subject string as its parameters. It returns True if the regular expression can match the string entirely. It returns False if the string cannot be matched or if it can only be matched partially. This is useful when using a regular expression to validate user input.
Do note that fullmatch() will return True if the subject string is the empty string and the regular expression can find zero-length matches. A zero-length match of a zero-length string is a complete match. So if you want to check whether the user entered a sequence of digits, use \d+ rather than \d* as the regex.
© Regular-Expressions.info or respective owner