#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time : 2018/8/21 13:58
# @author :
import re
while true:
# 匹配成功 返回乙個match物件 否則返回none
r = re.match(r'\d\-\d$', '010-123456')
email = input('輸入email:')
if email == 'exit':
break
r = re.match(r'[a-za-z0-9]+@[a-za-z0-9]+\.[a-za-z0-9]+', email)
if r:
print('ok')
else:
print('fail')
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time : 2018/8/21 14:15
# @author :
# 切分字串
sl1 = 'a b a a aaa'.split(' ')
print(sl1) # ['a', 'b', 'a', '', '', 'a', 'aaa']
import re
sl1 = re.split(r'\s+', 'a b a a aaa')
print(sl1) # ['a', 'b', 'a', 'a', 'aaa']
# 分組
m = re.match(r'(\d)-(\d)', '''010-123
215-12321
205-1232112''')
print(m.group(0)) # 010-123
print(m.group(1)) # 010
print(m.group(2)) # 123
# 貪婪模式
print(re.match(r'^(\d+)(0*)$', '12300').groups()) # ('12300', '') 這個是貪婪模式 所以 00沒有匹配出來
print(re.match(r'^(\d+?)(0*)$', '12300').groups()) # ('12300', '')
# 編譯
re_telphone = re.compile(r'^(\d)-(\d)$')
# 使用編譯好的正則
print(re_telphone.match('010-123').groups()) # ('010', '123')
print(re_telphone.match('010-123456').groups()) # ('010', '123456')
python學習作業筆記四
usr bin env python coding utf 8 time 2018 8 16 10 20 author 迭代器 可以迭代的資料都可以稱之為iterable物件 可迭代物件 from collections import iterable print isinstance iterab...
python學習作業筆記十一
usr bin env python coding utf 8 time 2018 8 20 17 01 author 多程序 from multiprocessing import process import os 子程序要執行的 def run proc name print run chil...
2013 7 15學習作業
題目1 int a 3 a 0 0 a 1 1 a 2 2 int p,q p a q a 2 a q p 的值是多少?為什麼?include using namespace std int main int argc,const char ar 題目2 const 有什麼用途?請用附上 例子佐證 ...