Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 11th, 2005, 03:55 AM
jeff sacksteder
Guest
 
Posts: n/a
Default regex help

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.
  #2  
Old August 11th, 2005, 04:15 AM
Christopher Subich
Guest
 
Posts: n/a
Default Re: regex help

jeff sacksteder wrote:[color=blue]
> 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.[/color]

Include the re.DOTALL flag when you compile the regular expression.
  #3  
Old August 11th, 2005, 12:25 PM
John Machin
Guest
 
Posts: n/a
Default Re: regex help

jeff sacksteder wrote:[color=blue]
> 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.[/color]

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.
"""
  #5  
Old August 11th, 2005, 10:25 PM
????? ????? (Shantanoo Mahajan)
Guest
 
Posts: n/a
Default Re: regex help

John Machin wrote:
[color=blue]
> jeff sacksteder wrote:[color=green]
>> 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.[/color]
>
> 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.
> """[/color]

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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles