Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python关于正则表达式_Python_Regex - Fatal编程技术网

Python关于正则表达式

Python关于正则表达式,python,regex,Python,Regex,我对使用正则表达式re 如果我只想在以下内容中打印处理器时间值0.394519574284646 Readings : \\demoweb01\processor(_total)\% processor time : 0.394519574284646 PSComputerName : DEMOWEB01 RunspaceId : 8c9e3d4b-8908-4a30-bef4-1f26d4a511bb Timestamp

我对使用正则表达式
re
如果我只想在以下内容中打印处理器时间值
0.394519574284646

Readings       : \\demoweb01\processor(_total)\% processor time :

                 0.394519574284646





PSComputerName : DEMOWEB01

RunspaceId     : 8c9e3d4b-8908-4a30-bef4-1f26d4a511bb

Timestamp      : 4/3/2017 2:39:30 PM

CounterSamples : {Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSa

                 mple}



Readings       : \\demoweb01\processor(_total)\% processor time :

                 1.69883362197086

它应该尝试在
处理器时间之后查找单词:
?另外,如何处理空行?

这里是处理空行和新行的正则表达式-

r'processor\s+time\s*:\s*(\d+(?:\.\d+)?)'
样本运行-

>>> output = """Readings       : \\demoweb01\processor(_total)\% processor time :
... 
...                  0.394519574284646
... 
... 
... 
... 
... 
... PSComputerName : DEMOWEB01
... 
... RunspaceId     : 8c9e3d4b-8908-4a30-bef4-1f26d4a511bb
... 
... Timestamp      : 4/3/2017 2:39:30 PM
... 
... CounterSamples : {Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSa
... 
...                  mple}
... 
... 
... 
... Readings       : \\demoweb01\processor(_total)\% processor time :
... 
...                  1.69883362197086"""
>>> import re
>>> re.findall(r'processor\s+time\s*:\s*(\d+(?:\.\d+)?)', output)
['0.394519574284646', '1.69883362197086']