Skip to content

Commit 5e3dcf9

Browse files
committed
add codec re
1 parent 4760cd9 commit 5e3dcf9

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

test_codec/test_codec.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#*--coding:utf-8--*
2+
import codecs
3+
import sys
4+
5+
print sys.maxunicode
6+
7+
mm = codecs.encode('hello world', 'gb2312')
8+
print codecs.decode(mm, 'gb2312')
9+
10+
print "风卷残云"
11+
a = u"风卷残云"
12+
13+
print codecs.encode(a, 'utf-8')
14+
print a.encode("utf-8")
15+
16+
look = codecs.lookup('gd2312')
17+
print look.decode(b)
18+
19+
20+
bfile = codecs.open("ddd.txt", 'r', 'bib5')
21+
ss = bfile.read()
22+
bfile.close()

test_re/test_re.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import re
2+
3+
mm = re.search('\Aab', 'abs')
4+
print mm.group(0)
5+
6+
mm = re.search('ab\Z', 'sab')
7+
print mm.group(0)
8+
9+
# mm = re.search(r'\bcsd', '1csd')
10+
# print mm.group(0)
11+
12+
mm = re.search(r'a\Bcsd', 'acsd')
13+
print mm.group(0)
14+
15+
mm = re.search('(ab)', 'absabsab')
16+
print mm.group()
17+
18+
mm = re.match('(ab)', 'absabsab')
19+
print mm.groups()
20+
21+
mm = re.findall('(ab)', 'absabsab')
22+
print mm
23+
24+
mm = re.search(r'\d(?<=\d)a', 'a3av')
25+
print mm.group(0)
26+
27+
28+
p = re.compile(r'\d+')
29+
for m in p.finditer('one1two2three3four4'):
30+
print m.group(),
31+
32+
print '\n'
33+
34+
p = re.compile(r'(\w+) (\w+)')
35+
s = 'i say, hello world'
36+
print p.sub(r'\2 \1', s)
37+
print p.subn(r'\2 \1', s)
38+
39+
m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcolm Reynolds")
40+
print m.groupdict()
41+
42+
43+
# mm = re.search('(?P<id>ab)', 'absabsab')
44+
45+
46+
# mm = re.search((?p<name>'ab'), 'absabsab')
47+
# print mm.group(0)
48+
49+

0 commit comments

Comments
 (0)