python 正規表示式過濾例項1
(1)print 展現字串:
>>> print res
lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 19-APR-2013 15:35:19
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.21.14)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 21-MAR-2013 22:42:02
Uptime 28 days 16 hr. 53 min. 17 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/product/10.2.0.5/network/admin/listener.ora
Listener Log File /oracle/product/10.2.0.5/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.21.14)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "st.anhui.wxxr.com.cn" has 1 instance(s).
Instance "wxxrdb", status READY, has 1 handler(s) for this service...
Service "st_XPT.anhui.wxxr.com.cn" has 1 instance(s).
Instance "wxxrdb", status READY, has 1 handler(s) for this service...
Service "wxxrdb" has 1 instance(s).
Instance "wxxrdb", status UNKNOWN, has 1 handler(s) for this service...
Service "wxxrdb.anhui.wxxr.com.cn" has 1 instance(s).
Instance "wxxrdb", status READY, has 1 handler(s) for this service...
Service "wxxrdbXDB.anhui.wxxr.com.cn" has 1 instance(s).
Instance "wxxrdb", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@anhuidbs ~]$
>>>
(2)裸展現:
>>> res
'lsnrctl status\r\n\r\nLSNRCTL for Linux: Version 10.2.0.5.0 - Production on 19-APR-2013 15:35:19\r\n\r\nCopyright (c) 1991, 2010, Oracle. All rights reserved.\r\n\r\nConnecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.21.14)(PORT=1521)))\r\nSTATUS of the LISTENER\r\n------------------------\r\nAlias LISTENER\r\nVersion TNSLSNR for Linux: Version 10.2.0.5.0 - Production\r\nStart Date 21-MAR-2013 22:42:02\r\nUptime 28 days 16 hr. 53 min. 17 sec\r\nTrace Level off\r\nSecurity ON: Local OS Authentication\r\nSNMP OFF\r\nListener Parameter File /oracle/product/10.2.0.5/network/admin/listener.ora\r\nListener Log File /oracle/product/10.2.0.5/network/log/listener.log\r\nListening Endpoints Summary...\r\n (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.21.14)(PORT=1521)))\r\n (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))\r\nServices Summary...\r\nService "PLSExtProc" has 1 instance(s).\r\n Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...\r\nService "st.anhui.wxxr.com.cn" has 1 instance(s).\r\n Instance "wxxrdb", status READY, has 1 handler(s) for this service...\r\nService "st_XPT.anhui.wxxr.com.cn" has 1 instance(s).\r\n Instance "wxxrdb", status READY, has 1 handler(s) for this service...\r\nService "wxxrdb" has 1 instance(s).\r\n Instance "wxxrdb", status UNKNOWN, has 1 handler(s) for this service...\r\nService "wxxrdb.anhui.wxxr.com.cn" has 1 instance(s).\r\n Instance "wxxrdb", status READY, has 1 handler(s) for this service...\r\nService "wxxrdbXDB.anhui.wxxr.com.cn" has 1 instance(s).\r\n Instance "wxxrdb", status READY, has 1 handler(s) for this service...\r\nThe command completed successfully\r\n[oracle@anhuidbs ~]$'
(3)處理要求:去掉展現的首行和最後一行 和空白行
p= re.compile(r'(^lsnrctl\s+status\s*)|(^\r\n)|(^\[.*\]\s*\$\s*)',re.M)
res2=p.sub('', res)
(4)處理以後展現:
>>> print res2
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 19-APR-2013 15:35:19
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.21.14)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 21-MAR-2013 22:42:02
Uptime 28 days 16 hr. 53 min. 17 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/product/10.2.0.5/network/admin/listener.ora
Listener Log File /oracle/product/10.2.0.5/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.21.14)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "st.anhui.wxxr.com.cn" has 1 instance(s).
Instance "wxxrdb", status READY, has 1 handler(s) for this service...
Service "st_XPT.anhui.wxxr.com.cn" has 1 instance(s).
Instance "wxxrdb", status READY, has 1 handler(s) for this service...
Service "wxxrdb" has 1 instance(s).
Instance "wxxrdb", status UNKNOWN, has 1 handler(s) for this service...
Service "wxxrdb.anhui.wxxr.com.cn" has 1 instance(s).
Instance "wxxrdb", status READY, has 1 handler(s) for this service...
Service "wxxrdbXDB.anhui.wxxr.com.cn" has 1 instance(s).
Instance "wxxrdb", status READY, has 1 handler(s) for this service...
The command completed successfully
(5)處理以後裸展現
'LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 19-APR-2013 15:35:19\r\nCopyright (c) 1991, 2010, Oracle. All rights reserved.\r\nConnecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.21.14)(PORT=1521)))\r\nSTATUS of the LISTENER\r\n------------------------\r\nAlias LISTENER\r\nVersion TNSLSNR for Linux: Version 10.2.0.5.0 - Production\r\nStart Date 21-MAR-2013 22:42:02\r\nUptime 28 days 16 hr. 53 min. 17 sec\r\nTrace Level off\r\nSecurity ON: Local OS Authentication\r\nSNMP OFF\r\nListener Parameter File /oracle/product/10.2.0.5/network/admin/listener.ora\r\nListener Log File /oracle/product/10.2.0.5/network/log/listener.log\r\nListening Endpoints Summary...\r\n (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.21.14)(PORT=1521)))\r\n (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))\r\nServices Summary...\r\nService "PLSExtProc" has 1 instance(s).\r\n Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...\r\nService "st.anhui.wxxr.com.cn" has 1 instance(s).\r\n Instance "wxxrdb", status READY, has 1 handler(s) for this service...\r\nService "st_XPT.anhui.wxxr.com.cn" has 1 instance(s).\r\n Instance "wxxrdb", status READY, has 1 handler(s) for this service...\r\nService "wxxrdb" has 1 instance(s).\r\n Instance "wxxrdb", status UNKNOWN, has 1 handler(s) for this service...\r\nService "wxxrdb.anhui.wxxr.com.cn" has 1 instance(s).\r\n Instance "wxxrdb", status READY, has 1 handler(s) for this service...\r\nService "wxxrdbXDB.anhui.wxxr.com.cn" has 1 instance(s).\r\n Instance "wxxrdb", status READY, has 1 handler(s) for this service...\r\nThe command completed successfully\r\n'
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27042095/viewspace-758903/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 正規表示式例項蒐集,通過例項來學習正規表示式。
- 通過js正規表示式例項學習正規表示式基本語法JS
- java正規表示式例項Java
- Java 正規表示式例項操作Java
- js正規表示式例項(整理)JS
- 正規表示式子表示式程式碼例項
- 正規表示式分組例項詳解
- 匹配中文正規表示式程式碼例項
- C#使用正規表示式過濾HTML程式碼C#HTML
- JavaScript正規表示式校驗非正整數例項JavaScript
- 驗證正整數正規表示式程式碼例項
- python正規表示式 小例幾則Python
- JavaScript正規表示式備忘單附例項JavaScript
- 解析url地址正規表示式程式碼例項
- 正規表示式獲取cookie程式碼例項Cookie
- javascript常用的正規表示式程式碼例項JavaScript
- 正規表示式刪除空格程式碼例項
- 正規表示式匹配空行程式碼例項行程
- vim的正規表示式(二)應用例項
- JS常用的匹配正規表示式和例項JS
- PHP preg match正規表示式函式的操作例項PHP函式
- java 正規表示式 舉例Java
- 匹配漢字的正規表示式程式碼例項
- 驗證小數正規表示式程式碼例項
- 郵箱驗證正規表示式例項程式碼
- 驗證ip地址正規表示式程式碼例項
- 匹配<a>連結的正規表示式程式碼例項
- 匹配數字的正規表示式程式碼例項
- Python——正規表示式Python
- Python 正規表示式Python
- Python:正規表示式Python
- python正規表示式Python
- JavaScript正規表示式校驗非零的正整數例項JavaScript
- JavaScript正規表示式校驗非負整數例項JavaScript
- 例項程式碼詳解正規表示式匹配換行
- 檢驗漢字的正規表示式程式碼例項
- Java經典例項:使用正規表示式:測試模式Java模式
- Java經典例項:正規表示式,找到匹配的文字Java