python - find all characters NOT in regex pattern -


let's have regex of legal characters

legals = re.compile("[abc]") 

i can return list of legal characters in string this:

finder = re.finditer(legals, "abcdefg") [match.group() match in finder] >>>['a', 'b', 'c'] 

how can use regex find list of characters not in regex? ie in case return

['d','e','f','g'] 

edit: clarify, i'm hoping find way without modifying regex itself.

negate character class:

>>> illegals = re.compile("[^abc]") >>> finder = re.finditer(illegals, "abcdefg") >>> [match.group() match in finder] ['d', 'e', 'f', 'g'] 

if can't (and you're dealing one-character length matches), could

>>> legals = re.compile("[abc]") >>> remains = legals.sub("", "abcdefg") >>> [char char in remains] ['d', 'e', 'f', 'g'] 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -