Matching Control Characters

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Mon Nov 1 11:36:31 EST 2004


Greg Lindstrom wrote:
> Hello-
> 
> I have a text file generated on a HP-9000 running HP-Unix with embedded
> control characters and would like to read it in, modify it, and write it out
> in PDF format.  The new page character is control-L which I can match with
> regular expressions as
> 
> /^M    (build using control-Q control-M)
> 
> but when I attempt to use this to match the string in the program using
> 
> if re.match('^M', input_line):    # using control-Q control-M
>    # issue a page feed
> 
> it will not match (no new pages are generated).
> 
> I am opening and reading the input file in binary mode.  Anyone see what I'm
> doing wrong?

Use the escape for Control-M: \x0D

Reinhold

-- 
[Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer
jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen
jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs-
mitteln inkompatibel.               -- Florian Diesch in dcoulm



More information about the Python-list mailing list