Without you explaining why 6 and 9 are invalid it's impossible to say how you should modify your regex to exclude them. You may find positive and negative look-ahead useful though.
As you can see, there is a lot of variations for the same file_id (1000). File_id (1001/1002) is a new unassigned file, different from the others.
I wanna be able to get ONLY the 'master' variation ( /testfile/client/10/attachment/1000/master/ ) and the unassigned files variations [if any] (/testfile/client/10/attachment/unassigned/file/1001/master | /testfile/client/10/attachment/unassigned/file/1002/master).
So on the demo above, only id IN (5,9,10) are valid for me. The SELECT that I used as an example is not returning me ONLY the data I need, instead, it is returning (almost) everything.
To summarize: I wanna use a pattern matching the only returns these rows: