Skip to content
Advertisement

Remove text lines and strip lines with condition in python

I have a text file in this format:

JavaScript

I want to remove the lines that don’t have a [number1,number2,number3,number4,1] or [number1,number2,number3,number4,5] ending and also strip the text line and remove the [blocks] -> [number1,number2,number3,number4,number5] that don’t fulfill this condition.

The above text file should look like this in the end:

JavaScript

My code:

JavaScript

I have tried something like this and it didn’t work obviously.

Advertisement

Answer

No need for Regex, this might help you:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement