regex help
????? ????? (Shantanoo Mahajan)
shantanoo at gmail.com
Thu Aug 11 17:14:54 EDT 2005
John Machin wrote:
> jeff sacksteder wrote:
>> Regex questions seem to be rather resistant to googling.
>>
>> My regex currently looks like - 'FOO:.*\n\n'
>>
>> The chunk of text I am attempting to locate is a line beginning with
>> "FOO:", followed by an unknown number of lines, terminating with a
>> blank line. Clearly the ".*" phrase does not match the single newlines
>> occuring inside the block.
>>
>> Suggestions are warmly welcomed.
>
> I suggest you read the manual first:
> """
> "."
> (Dot.) In the default mode, this matches any character except a newline.
> If the DOTALL flag has been specified, this matches any character
> including a newline.
> """
I think you need to write you own function. Something like:
for x in open('_file_name'):
if x == 'Foo:\n':
flag=1
if x == '\n':
flag=0
if flag == 1:
print x
if the line is 'FOO: _some_more_data_' you may try,
if x.startswith('Foo:'):
instead of
if x == 'Foo:\n':
Hope this help.
Shantanoo
More information about the Python-list
mailing list