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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27042095/viewspace-758903/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值