Is it possible in python to convert a string e.g.
"[A-Z]" to "ABCDE...XYZ"
or
"[0-9]" to "012..9"
or other similar REs
by using the re
python module.
Is it possible in python to convert a string e.g.
"[A-Z]" to "ABCDE...XYZ"
or
"[0-9]" to "012..9"
or other similar REs
by using the re
python module.
Regular expressions are about matching, not generation.
You can, of course, pre-generate a sequence of all characters you care about and then match your RE against it, selecting only the matching ones.
import re
all_chars = "".join(chr(x) for x in range(32, 128)) # only ASCII here
digits_and_caps_rx = re.compile('([0-9]|[A-Z])')
print "".join(digits_and_caps_rx.findall(all_chars))