[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
form (?:) can be used to group nested parts of a pattern without forming a saved substring group (split treats groups specially) ...
locate and extract bracketed text anywhere in a string, even pairs with optional text between: >>> '<spam>/<ha ...
('aaa', 'bbb', 'ccc') >>> line.split() # split data with fixed delimiters ['aaa', 'bbb', 'ccc'] >>> re.split(' ...
split(pattern, string [, maxsplit, flags]) Split string by occurrences of pattern. If capturing parentheses (()) are used in the ...
groups() Returns a tuple of all groups’ substrings of the match (for group numbers 1 and higher). groupdict() Returns a dictiona ...
Operator Interpretation R|R Alternative: matches left or right R RR Concatenation: match both Rs (R) Matches any regular express ...
Table 19-2. re special sequences Sequence Interpretation \number Matches text of group number (numbered from 1) \A Matches only ...
print(matchobj.start()) selection sets print(re.search(" *A.C[DE][D-F][^G-ZE]G\t+ ?", "..ABCDEFG\t..").start()) alternatives: R1 ...
The second test’s (.*) groups match and retain any number of characters. The third and fourth tests shows how alternatives can b ...
Example 19-6. PP4E\Lang\cheader.py "Scan C header files to extract parts of #define and #include lines" import sys, re pattDefin ...
C:\...\PP4E\Lang> python cheader.py test.h 2 defined TEST_H = 4 include stdio.h 5 include lib/spam.h 6 include Python.h 8 def ...
Beyond these parsing tools, Python also ships with an xmlrpc package to support the client and server sides of the XML-RPC proto ...
Let’s quickly explore ways to extract this file’s book ISBN numbers and corresponding titles by example, using each of the four ...
Example 19-10. PP4E\Lang\Xml\saxbook.py """ XML parsing: SAX is a callback-based API for intercepting parser events """ import x ...
C:\...\PP4E\Lang\Xml> python saxbook.py {'0-596-00128-2': 'Python & XML', '0-596-00797-3': 'Python Cookbook, 2nd Edition' ...
'0-596-00797-3': 'Python Cookbook, 2nd Edition', '0-596-10046-9': 'Python in a Nutshell, 2nd Edition', '0-596-15806-8': 'Learnin ...
Other XML topics Naturally, there is much more to Python’s XML support than these simple examples imply. In deference to space, ...
>>> from html.parser import HTMLParser >>> class ParsePage(HTMLParser): ... def handle_starttag(self, tag, att ...
Handling HTML entity references (revisited) Here’s another HTML parsing example: in Chapter 15, we used a simple method ex- port ...
Extracting plain text from HTML (revisited) Now that you understand the basic principles of the HTML parser class in Python’s st ...
«
69
70
71
72
73
74
75
76
77
78
»
Free download pdf