Python: Regex and String Length in byte -
i writing program in python , have question (i 100% new python):
import re rawdata = '7i+8i-7i-9i-8i-' print len(rawdata) rawdata = re.sub("[0-9]i\+","",rawdata) rawdata = re.sub("[0-9]i\-","",rawdata) print rawdata
- how merge 2 regex 1 using
|
? means rid of both9i-
,9i+
using 1 regex operation. - does len(rawdata) return length of rawdata byte?
thank you.
see difference:
$ python3 python 3.1.3 (r313:86834, may 20 2011, 06:10:42) [gcc 4.4.5] on linux2 type "help", "copyright", "credits" or "license" more information. >>> len('día') # unicode text 3 >>> $ python python 2.7.1 (r271:86832, may 20 2011, 17:19:04) [gcc 4.4.5] on linux2 type "help", "copyright", "credits" or "license" more information. >>> len('día') # bytes 4 >>> len(u'día') # unicode text 3 >>> python 3.1.3 (r313:86834, may 20 2011, 06:10:42) [gcc 4.4.5] on linux2 type "help", "copyright", "credits" or "license" more information. >>> len(b'día') file "<stdin>", line 1 syntaxerror: bytes can contain ascii literal characters. >>> len(b'dia') 3 >>>
Comments
Post a Comment