Python regex pattern from array of hex chars

Joseph L. Casale jcasale at activenetwerx.com
Fri Apr 13 13:28:01 EDT 2018


I have an array of hex chars which designate required characters.
and one happens to be \x5C or "\". What foo is required to build the
pattern to exclude all but:

regex = re.compile('[^{}]+'.format(''.join(c for c in character_class)))

I would use that in a re.sub to collapse and replace all but those
in the character_class. Obviously the escape issues break the \x5C
character.

Thanks,
jlc



More information about the Python-list mailing list