RegEx to match set of lines

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Apr 5 11:03:31 EDT 2018


On Thu, 05 Apr 2018 14:09:23 +0530, Prahallad Achar wrote:

> Hello,
> I would like to match set of lines from the below data. this data comes
> from one of the network

Good grief! You don't need to post your entire data set! We don't need or 
want to see hundreds of lines.

Cut your data down to a SMALL representative sample. Explain how it is 
coming to you: it looks like you are reading the data in something 
similar to key:value format. Is that correct?

If so, you don't need a regex. This is not Perl, we have more than one 
tool in our toolbox and don't have to force everything to be a regex.

The way I would process it would be to write a small accumulator function 
to group the lines into records, then a filter function to extract the 
records you want, and finally a function to extract the specific values 
you want from the record.

Far more understandable and maintainable, and less fragile, than a 
horribly complex regex.


-- 
Steve




More information about the Python-list mailing list