June 2000
Intermediate to advanced
556 pages
8h 45m
English
Finally(!) it is time to add regular expression support to xgrep. Here is the code for the XMLGrep function of xgrep.py modified to allow the use of regular expressions.
CD-ROM reference=7064.txt import string,os #import regular expressions module import re def XMLGrep(filename,pattern,MarkHits=0): # Create a regular expression object out of the # specified pattern Pat = re.compile (pattern) # MarkHits is an optional parameter; it defaults to 0 # if not specified. if MarkHits == 0: # Do not mark hits, make hit delimiters blank # strings. StartOfHit = "" EndOfHit = "" else: # Mark hits, make hit delimiters matching square # brackets. StartOfHit = "[" EndOfHit = "]" f = open (filename,'r') for L in f.readlines(): ...
Read now
Unlock full access