當前位置:成語大全網 - 新華字典 - Python 腳本之統計基因組文件中染色體長度及N堿基數目

Python 腳本之統計基因組文件中染色體長度及N堿基數目

re模塊是Python中的正則表達式調用模塊,在python中,通過將正則表達式內嵌集成re模塊,程序員們可以直接調用來實現正則匹配。

正則表達式的大致匹配過程是:

re模塊所支持的方法有如下:

其中,pattern為匹配模式,由re.compile生成,例如: pattern = re.compile(r'hello')

參數flag是匹配模式,取值可以使用按位或運算符’|’表示同時生效,如 re.I | re.M。可選值有:

註:以上七個方法中的flags同樣是代表匹配模式的意思,如果在pattern生成時已經指明了flags,那麽在下面的方法中就不需要傳入這個參數了。

1. re.match(pattern, string[, flags])

2. re.search(pattern, string[, flags])

3. re.split(pattern, string[, maxsplit])

4. re.findall(pattern, string[, flags])

5. re.finditer(pattern, string[, flags])

6. re.sub(pattern, repl, string[, count])

7. re.subn(pattern, repl, string[, count])

描述

註意:該方法只能刪除開頭或是結尾的字符,不能刪除中間部分的字符。

語法

參數

返回值

實例

以上實例輸出結果如下:

參考

blogs.com/chengege/p/11190782.html

/python/att-string-strip.html