re庫主要功能函式

2021-08-01 18:38:25 字數 1667 閱讀 7296

#coding=utf-8

import re

#re.search(pattern, string, flags)

匹配正規表示式的第乙個位置,返回

match

物件match = re.search(r'[1-9]\d', 'bit 100081')

if match:

print match.group(0)

#re.match(pattern, string, flags)

從字串的開始位置匹配正規表示式,返回

match物件#

不調整引數時會報錯

#match = re.match(r'[1-9]\d', 'bit 100081')

#調整引數

match = re.match(r'[1-9]\d', '100081bit')

if match:

print match.group(0)#報錯

# print match.group(0)

# traceback (most recent call last):

# file "c:/users/administrator/pythonworkspace/python14.py", line 10, in

# print match.group(0)

# attributeerror100081

# : 'nonetype' object has no attribute 'group'

#re.findall(pattern, string, flags)

以列表型別返回全部能匹配的子串

ls = re.findall(r'[1-9]\d', 'bit100081 tsu100084')

print ls

#re.split(pattern, string, maxsplit, flags)

將字串按照正規表示式匹配結果進行分割,返回列表型別

#maxsplit:

最大分割數

ls = re.split(r'[1-9]\d', 'bit100081 tsu100084')

print ls

ls = re.split(r'[1-9]\d', 'bit100081 tsu100084', 1)

print ls #

只匹配第乙個

#re.finditer(pattern, string, flags)

返回乙個匹配結果的迭代型別,每個迭代元素都是

match

物件for m in re.finditer(r'[1-9]\d', 'bit100081 tsu100084'):

if m:

print m.group(0)

#re.sub(pattern, repl, string,count=0, flags=0)

在乙個字串中替換所有匹配正規表示式的子串,返回替換後的字串

#repl:

替換匹配字串的字串

#count

:匹配的最大替換次數

print re.sub(r'[1-9]\d', ':zipcode', 'bit100081 tsu100084')

print re.sub(r'[1-9]\d', ':zipcode', 'bit100081 tsu100084', 1)

Valgrind的主要功能

valgrind是乙個gpl的軟體,用於linux for x86,amd64 and ppc32 程式的記憶體除錯和 剖析。你可以在它的環境中執行你的程式來監視記憶體的使用情況,比如c 語言中的malloc和free或者 c 中的new和 delete。使用 valgrind的工具包,你可以自動的...

Mongodb主要功能特點

mongodb無模式優點 1 儲存形式,相較於傳統的關係型資料庫,它可以使用乙個表儲存原來需要使用多表關聯才能儲存的資料庫。2 儲存動態性,相較於傳統的資料庫當要增加乙個屬性值的時候要對表大動,mongodb的面向文件的形式可以使其屬性值輕意的增加和刪除。而原來 的關係型資料庫要實現這個需要有很多的...

DBMS的主要功能

概述 這五個功能就像dbms的乙個目錄,因為沒有涉及到很多的細節和實用性的技術,所以目前來講沒有多大的價值,如果在深入到細節之後再總覽,就會更加深入地把握好。這五個功能是怎麼提出來的?第1 5個功能是技術上 第2 3 4個功能是實踐需要,根據現實需要不斷完善的,這是需要積累經驗的。提這個問題有什麼意...