0

So I'm reading an .avi file and storing it's index into a list. Each element corresponds to an index movie frame. I'm working on a script to delete all the occurrences in the list that start with :

00dc\x10\x00\x00\x00

Here's a short version of the code

   list = ['00dc\x00\x00\x00\x00\x025,\x00\x08\x19\x00\x00',
        '00dc\x00\x00\x00\x00\x12N,\x00\x0b6\x00\x00',
        '00dc\x10\x00\x00\x00&\x84,\x00\x95D\x01\x00',
        '00dc\x00\x00\x00\x00\xc4\xc8-\x00\xe0l\x00\x00',
        '00dc\x00\x00\x00\x00\xac5.\x00t.\x00\x00']

    regex1 = b'00dc\x10\x00\x00\x00.{8}'
    newlist = [x for x in list if x != regex1]

Aaand it doesn't do anything, the list stays the same when I expected the third element to be popped out.

I don't think it matches anything because even when I set the regex1 to :

b'.*'

The list stays the same. Having trouble figuring out where the issue is coming from. Thanks

1 Answer 1

1

Python doesn't work with regex built-in. You need to import regex module.

import re
list = ['00dc\x00\x00\x00\x00\x025,\x00\x08\x19\x00\x00',
        '00dc\x00\x00\x00\x00\x12N,\x00\x0b6\x00\x00',
        '00dc\x10\x00\x00\x00&\x84,\x00\x95D\x01\x00',
        '00dc\x00\x00\x00\x00\xc4\xc8-\x00\xe0l\x00\x00',
        '00dc\x00\x00\x00\x00\xac5.\x00t.\x00\x00']

pattern = re.compile(b'00dc\x10\x00\x00\x00.{8}')
newlist = [x for x in list if not re.match(pattern,x)]

Output:

['00dc\x00\x00\x00\x00\x025,\x00\x08\x19\x00\x00', '00dc\x00\x00\x00\x00\x12N,\x00\x0b6\x00\x00', '00dc\x00\x00\x00\x00\xc4\xc8-\x00\xe0l\x00\x00', '00dc\x00\x00\x00\x00\xac5.\x00t.\x00\x00']
Sign up to request clarification or add additional context in comments.

1 Comment

thanks ! I had imported re, just totally forgot I should compile and match :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.