我试图将下面的字符串与正则表达式匹配并从中获取一些值。
/system1/sensor37
Targets
Properties
DeviceID=37-Fuse
ElementName=Power Supply
OperationalStatus=Ok
RateUnits=Celsius
CurrentReading=49
SensorType=Temperature
HealthState=Ok
oemhp_CautionValue=100
oemhp_CriticalValue=Not Applicable
为此使用了以下正则表达式
`/system1/sensor\d\d\n.*\n.*\n\s*DeviceID=(?P<sensor>.*)\n.*\n.*\n.*\n\s*CurrentReading=(?P<reading>\d*)\n\s*SensorType=Temperature\n\s*HealthState=(?P<health>.*)\n`
现在我的问题是:有更好的方法吗?我明确提到了字符串中的每个新行和空白组。但是我可以说/system.sensor\d\d.*DeviceID=(?P<sensor>.*)\n*.
(它对我不起作用,但我相信应该有办法。)