标签:http base import 搜索 tput one arch attach 使用

|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# encoding: UTF-8import re# 将正则表达式编译成Pattern对象pattern = re.compile(r‘world‘)# 使用search()查找匹配的子串,不存在能匹配的子串时将返回None# 这个例子中使用match()无法成功匹配match = pattern.search(‘hello world!‘)if match: # 使用Match获得分组信息 print match.group()### 输出 #### world |
|
1
2
3
4
5
6
7
|
import rep = re.compile(r‘\d+‘)print p.split(‘one1two2three3four4‘)### output #### [‘one‘, ‘two‘, ‘three‘, ‘four‘, ‘‘] |
|
1
2
3
4
5
6
7
|
import rep = re.compile(r‘\d+‘)print p.findall(‘one1two2three3four4‘)### output #### [‘1‘, ‘2‘, ‘3‘, ‘4‘] |
|
1
2
3
4
5
6
7
8
|
import rep = re.compile(r‘\d+‘)for m in p.finditer(‘one1two2three3four4‘): print m.group(),### output #### 1 2 3 4 |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import rep = re.compile(r‘(\w+) (\w+)‘)s = ‘i say, hello world!‘print p.sub(r‘\2 \1‘, s)def func(m): return m.group(1).title() + ‘ ‘ + m.group(2).title()print p.sub(func, s)### output #### say i, world hello!# I Say, Hello World! |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import rep = re.compile(r‘(\w+) (\w+)‘)s = ‘i say, hello world!‘print p.subn(r‘\2 \1‘, s)def func(m): return m.group(1).title() + ‘ ‘ + m.group(2).title()print p.subn(func, s)### output #### (‘say i, world hello!‘, 2)# (‘I Say, Hello World!‘, 2) |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# encoding: UTF-8import re# 将正则表达式编译成Pattern对象pattern = re.compile(r‘world‘)# 使用search()查找匹配的子串,不存在能匹配的子串时将返回None# 这个例子中使用match()无法成功匹配match = pattern.search(‘hello world!‘)if match: # 使用Match获得分组信息 print match.group()### 输出 #### world |
|
1
2
3
4
5
6
7
|
import rep = re.compile(r‘\d+‘)print p.split(‘one1two2three3four4‘)### output #### [‘one‘, ‘two‘, ‘three‘, ‘four‘, ‘‘] |
|
1
2
3
4
5
6
7
|
import rep = re.compile(r‘\d+‘)print p.findall(‘one1two2three3four4‘)### output #### [‘1‘, ‘2‘, ‘3‘, ‘4‘] |
|
1
2
3
4
5
6
7
8
|
import rep = re.compile(r‘\d+‘)for m in p.finditer(‘one1two2three3four4‘): print m.group(),### output #### 1 2 3 4 |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import rep = re.compile(r‘(\w+) (\w+)‘)s = ‘i say, hello world!‘print p.sub(r‘\2 \1‘, s)def func(m): return m.group(1).title() + ‘ ‘ + m.group(2).title()print p.sub(func, s)### output #### say i, world hello!# I Say, Hello World! |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import rep = re.compile(r‘(\w+) (\w+)‘)s = ‘i say, hello world!‘print p.subn(r‘\2 \1‘, s)def func(m): return m.group(1).title() + ‘ ‘ + m.group(2).title()print p.subn(func, s)### output #### (‘say i, world hello!‘, 2)# (‘I Say, Hello World!‘, 2) |
标签:http base import 搜索 tput one arch attach 使用
原文地址:http://www.cnblogs.com/niubin/p/7082299.html