Python String replace based on chars NOT in RegEx -


is possible create reqex finds characters not specific set?

rather blacklisting bunch of characters , replacing them, easier me allow set , replace characters not in set.

my set looks this: [.a-za-z0-9]

i this:

clean_filename = re.sub(r'([.a-za-z0-9])', "_", filename) 

obviously code replace characters want keep, there way replace characters not in set?

yes, use ^ negation "modifier": r'[^.a-za-z0-9]'


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -