Python Tutorial ( PDFDrive )
[^0-9]Special Character Classes: Match anything other than a digitExampleDescription. Match any character except newline\d Match a digit: [0-9]\D Match a nondigit: [^0-9]\s Match a whitespace character: [ \t\r\n\f]\S Match nonwhitespace: [^ \t\r\n\f]\w Match a single word character: [A-Za-z0-9_]\W Match a nonword character: [^A-Za-z0-9_]Repetition Cases: Exampleruby?ruby*ruby+\d{3}\d{3,}DescriptionMatch "rub" or "ruby": the y is optionalMatch "rub" plus 0 or more ysMatch "rub" plus 1 or more ysMatch exactly 3 digitsMatch 3 or more digits\d{3,5}Match 3, 4, or 5 digitsNongreedy repetition: This matches the smallest number of repetitions:ExampleDescription<.*> Greedy repetition: matches "<python>perl>"<.*?> Nongreedy: matches "<python>" in "<python>perl>"Grouping with parentheses: ExampleDescription\D\d+ No group: + repeats \d(\D\d)+([Pp]ython(, )?)+Grouped: + repeats \D\d pairMatch "Python", "Python, python, python", etc.TUTORIALS POINT Simply Easy Learning
Backreferences: This matches a previously matched group again:Example([Pp])ython&\1ails(['"])[^\1]*\1Alternatives: Examplepython|perlrub(y|le))DescriptionMatch python&pails or Python&PailsSingle or double-quoted string. \1 matches whatever the 1st group matched . \2 matcheswhatever the 2nd group matched, etc.DescriptionMatch "python" or "perl"Match "ruby" or "ruble"Python(!+|\?) "Python" followed by one or more ! or one ?Anchors: This needs to specify match position.Example^PythonPython$\APythonPython\Z\bPython\b\brub\BPython(?=!)DescriptionMatch "Python" at the start of a string or internal lineMatch "Python" at the end of a string or lineMatch "Python" at the start of a stringMatch "Python" at the end of a stringMatch "Python" at a word boundary\B is nonword boundary: match "rub" in "rube" and "ruby" but not aloneMatch "Python", if followed by an exclamation pointPython(?!!)Match "Python", if not followed by an exclamation pointSpecial syntax with parentheses: ExampleR(?#comment)R(?i)ubyR(?i:uby)rub(?:y|le))DescriptionMatches "R". All the rest is a commentCase-insensitive while matching "uby"Same as aboveGroup only without creating \1 backreferenceTUTORIALS POINT Simply Easy Learning
- Page 273 and 274: # Close opened fileos.close( fd )#
- Page 275 and 276: dev_num = os.makedev(major_dnum, mi
- Page 277 and 278: Return Value This method does not
- Page 279 and 280: -rw-------. 1 root root 0 Apr 30 02
- Page 281 and 282: os.pathconf(path, name) Descriptio
- Page 283 and 284: Description The method popen() open
- Page 285 and 286: # !/usr/bin/pythonimport ossrc = '/
- Page 287 and 288: Syntax Following is the syntax for
- Page 289 and 290: Return Value This method does not
- Page 291 and 292: # stat informationstatinfo = os.sta
- Page 293 and 294: Description The method tcgetpgrp()
- Page 295 and 296: os.tempnam(dir, prefix)Parameters
- Page 297 and 298: Description The method ttyname() re
- Page 299 and 300: Return Value This method does not
- Page 301 and 302: Return Value This method returns t
- Page 303 and 304: KeyErrorNameErrorUnboundLocalErrorE
- Page 305 and 306: ......................else:If there
- Page 307 and 308: print "Error: can\'t find file or r
- Page 309 and 310: self.args = argSo once you defined
- Page 311 and 312: 'Optional class documentation strin
- Page 313 and 314: For the above class let's try to ac
- Page 315 and 316: print 'Calling child method'c = Chi
- Page 317 and 318: Data Hiding: An object's attribute
- Page 319 and 320: groups()This method returns all mat
- Page 321 and 322: SYNTAX: re.sub(pattern, repl, strin
- Page 323: \s Matches whitespace. Equivalent t
- Page 327 and 328: CHAPTER20Python CGI ProgrammingWhat
- Page 329 and 330: If you click hello.py, then this pr
- Page 331 and 332: Simple URL Example : Get Metho
- Page 333 and 334: </form>The result of this code is t
- Page 335 and 336: text_content = form.getvalue('textc
- Page 337 and 338: Here is an example of how to retrie
- Page 339 and 340: CHAPTER21Python Database AccessThe
- Page 341 and 342: EXAMPLE: Following is the example o
- Page 343 and 344: ('Mac', 'Mohan', 20, 'M', 2000)try:
- Page 345 and 346: DELETE Operation: DELETE operation
- Page 347 and 348: ProgrammingErrorSubclass of Databas
- Page 349 and 350: The socket Module: To create a so
- Page 351 and 352: Protocol Common function Port No Py
- Page 353 and 354: Subject: SMTP e-mail testThis is a
- Page 355 and 356: try:smtpObj = smtplib.SMTP('localho
- Page 357 and 358: count = 0while count < 5:time.sleep
- Page 359 and 360: Synchronizing Threads: The threadi
- Page 361 and 362: thread = myThread(threadID, tName,
- Page 363 and 364: <stars>10</stars><description>Talk
- Page 365 and 366: print "Rating:", self.ratingelif se
- Page 367 and 368: Format: DVDRating: PGDescription: T
- Page 369 and 370: Tkinter Widgets Tkinter provides v
- Page 371 and 372: fgfontheighthighlightcolorimagejust
- Page 373 and 374: WidthXscrollincrementXscrollcommand
[^0-9]
Special Character Classes:
Match anything other than a digit
Example
Description
. Match any character except newline
\d Match a digit: [0-9]
\D Match a nondigit: [^0-9]
\s Match a whitespace character: [ \t\r\n\f]
\S Match nonwhitespace: [^ \t\r\n\f]
\w Match a single word character: [A-Za-z0-9_]
\W Match a nonword character: [^A-Za-z0-9_]
Repetition Cases:
Example
ruby?
ruby*
ruby+
\d{3}
\d{3,}
Description
Match "rub" or "ruby": the y is optional
Match "rub" plus 0 or more ys
Match "rub" plus 1 or more ys
Match exactly 3 digits
Match 3 or more digits
\d{3,5}
Match 3, 4, or 5 digits
Nongreedy repetition:
This matches the smallest number of repetitions:
Example
Description
<.*> Greedy repetition: matches "<python>perl>"
<.*?> Nongreedy: matches "<python>" in "<python>perl>"
Grouping with parentheses:
Example
Description
\D\d+ No group: + repeats \d
(\D\d)+
([Pp]ython(, )?)+
Grouped: + repeats \D\d pair
Match "Python", "Python, python, python", etc.
TUTORIALS POINT
Simply Easy Learning