所以,这是示例文本:
Huawei Integrated Access Software (MA5683T).
Copyright(C) Huawei Technologies Co., Ltd. 2002-2013. All rights reserved.
-----------------------------------------------------------------------------
User last login information:
-----------------------------------------------------------------------------
Access Type : SSH
IP-Address : 0.0.0.0 ssh
Login Time : 07.02.2017 20:01:48+01:00
Logout Time : 07.02.2017 20:01:59+01:00
-----------------------------------------------------------------------------
MA5683T>enable
MA5683T#display ont autofind all
----------------------------------------------------------------------------
Number : 1
F/S/P : 0/4/0
Ont SN : 48575443E1EAC883 (HWTC-E1EAC883)
Password : 0x00000000000000000000
Loid :
Checkcode :
VendorID : HWTC
Ont Version : 635.A
Ont SoftwareVersion : V3R015C10S106
Ont EquipmentID : 010H
Ont autofind time : 06.02.2017 11:35:08+01:00
----------------------------------------------------------------------------
Number : 2
F/S/P : 0/4/0
Ont SN : 48575443ED9B1582 (HWTC-ED9B1582)
Password : 0x00000000000000000000
Loid :
Checkcode :
VendorID : HWTC
Ont Version : 635.A
Ont SoftwareVersion : V3R015C10S106
Ont EquipmentID : 010H
Ont autofind time : 07.02.2017 15:57:35+01:00
----------------------------------------------------------------------------
Number : 3
F/S/P : 0/4/1
Ont SN : 48575443E1DA5683 (HWTC-E1DA5683)
Password : 0x00000000000000000000
Loid :
Checkcode :
VendorID : HWTC
Ont Version : 635.A
Ont SoftwareVersion : V3R015C10S106
Ont EquipmentID : 010H
Ont autofind time : 07.02.2017 09:20:57+01:00
----------------------------------------------------------------------------
The number of GPON autofind ONT is 3
MA5683T#
我需要提取“Ont SN”(例如48575443E1EAC883)和“F”,“S”和“P”值(文本中的F / S / P:0/4/0)。
输出将是:
$serial = "48575443E1EAC883"
$f = 0
$s = 4
$p = 0
因为有3条记录,除以------行,我需要放入数组。
感谢您的建议。
答案 0 :(得分:1)
匹配 Ont SN :
/Ont SN\s*:\s*([\w]+)/g
https://regex101.com/r/Q7zuk1/1
匹配 F / S / P :
/F\/S\/P\s*:\s*(\d+)\/(\d+)\/(\d+)/g