Confusion python or programmer?
I have many lines like this:
some_dict[0x2a] = blah
some_dict[0xab] = blah, blah
What I would like to do is convert the hexadecimal codes to all uppercase letters to look like this:
some_dict[0x2a] = blah
some_dict[0xab] = blah, blah
So I decided to call regular expressions. Usually I just do it with my regexps (xemacs) editor, but having to convert to uppercase puts it in Lisp ..... ok ... what about Python?
So, I am sleeping a short script that does not work. I have compressed the code in this example, which also does not work. It seems to me that Python regular expressions get confused by parentheses in the code. Is it me or Python?
import fileinput
import sys
import re
this = "0x2a"
that = "[0x2b]"
for line in [this, that]:
found = re.match("0x([0-9,a-f]{2})", line)
if found:
print("Found: %s" % found.group(0))
(I use grouping () constructors, so I do not use the value "x" in "0x".)
0x2a, 0x2b. ?
, :
found = re.match("\[0x([0-9,a-f]{2}\])", line)
, - , .
Python 2.6.2 Linux.