[Tutor] Text matching

Kent Johnson kent37 at tds.net
Thu May 3 14:45:38 CEST 2007


Gardner, Dean wrote:
> Hi Folks
> 
> I wish to isolate certain changelog entries and display them to the 
> user, for example:
> 
> Changelog.txt
> 
> ----------Some Module <Tag> ----------
> M 000751 - Title
>>  what was amended
> Reviewed by: Someone
> 
> For this text file I wish to find all entries for 000751 and then 
> present each of the changelog entries.
> 
> My thought was to
> identify the "----" with a regular expression
> identifying this as the changelog start

You probably don't need a regex here, something like
   if line.startswith('----------'):
will probably work

> attempt to find the item number

   if line.split()[1] == '000751':

> if it isn't found move on, if it is found then add this to a list.
> 
> But I feel as though there must be a simpler and more effecient way.

This sounds good to me except for the regex. Can you show us your code?

Kent



More information about the Tutor mailing list