How to block all users not containing a pattern?
I suggest use drush block 

drush ublk $(drush sqlq 'SELECT GROUP_CONCAT(ufd.name) FROM users u join user__roles ur on  u.uid = ur.entity_id  join users_field_data ufd on ufd.uid = u.uid where ur.roles_target_id ="YOUR_ROLE_MACHINENAME" and ufd.name like "%PATTERN%"')


before that make sure the query is correct and it respond what you want by 

drush sqlq 'SELECT GROUP_CONCAT(ufd.name) FROM users u join user__roles ur on  u.uid = ur.entity_id  join users_field_data ufd on ufd.uid = u.uid where ur.roles_target_id ="YOUR_ROLE_MACHINENAME" and ufd.name like "%PATTERN%"


and finally, make sure they are blocked by checking "User status" column of the result of the following command

drush uinf $(drush sqlq 'SELECT GROUP_CONCAT(ufd.name) FROM users u join user__roles ur on  u.uid = ur.entity_id  join users_field_data ufd on ufd.uid = u.uid where ur.roles_target_id ="YOUR_ROLE_MACHINENAME" and ufd.name like "%PATTERN%"')


PS: 


YOUR_ROLE_MACHINENAME: change it with your desired role.      
PATTERN: you can use MySQL LIKE statement