June 2000
Intermediate to advanced
556 pages
8h 45m
English
The following example is an XML-aware grep for phrases beginning with “g” and ending in “t.” The search is restricted to character data. Therefore, we do not get any false hits such as the <greeting> start-tag.
CD-ROM reference=8012.txt
C>python xgrep1.py -m -p g.*t -e greeting.xml
greeting.xml(Character Data): [greeting from greet]ing-land.
The pattern here, g.*t is a Python regular expression. Notice how the output includes not only the filename, but also the type of XML event that caused the match—in this case, character data. Notice also how the resultant match has “skipped over” the “t” in the the first occurrence of “greeting” and extended as far as the second one. This is a consequence of the fact that Python pattern ...
Read now
Unlock full access