changeset: 74003:766a21ebf82e branch: 2.7 parent: 73987:f2a5dcced66d user: Ezio Melotti date: Sat Dec 17 01:17:17 2011 +0200 files: Doc/library/re.rst description: #13613: fix example in re doc. diff -r f2a5dcced66d -r 766a21ebf82e Doc/library/re.rst --- a/Doc/library/re.rst Thu Dec 15 21:42:03 2011 +0100 +++ b/Doc/library/re.rst Sat Dec 17 01:17:17 2011 +0200 @@ -1000,16 +1000,16 @@ Suppose you are writing a poker program where a player's hand is represented as a 5-character string with each character representing a card, "a" for ace, "k" -for king, "q" for queen, j for jack, "0" for 10, and "1" through "9" +for king, "q" for queen, "j" for jack, "t" for 10, and "2" through "9" representing the card with that value. To see if a given string is a valid hand, one could do the following: ->>> valid = re.compile(r"[0-9akqj]{5}$") ->>> displaymatch(valid.match("ak05q")) # Valid. - "" ->>> displaymatch(valid.match("ak05e")) # Invalid. ->>> displaymatch(valid.match("ak0")) # Invalid. +>>> valid = re.compile(r"^[a2-9tjqk]{5}$") +>>> displaymatch(valid.match("akt5q")) # Valid. + "" +>>> displaymatch(valid.match("akt5e")) # Invalid. +>>> displaymatch(valid.match("akt")) # Invalid. >>> displaymatch(valid.match("727ak")) # Valid. ""

AltStyle によって変換されたページ (->オリジナル) /