我有一个批处理文件,它从远程服务器提取信息并显示我的一项服务的信息。
我使用的批处理如下:
tasklist /s TESTING1 /u TESTSvc /p T$ST1ng /fi "services eq test"
当我运行批处理时,我会收到信息,但需要创建一个正则表达式,让我知道内存是否大于一定数量。我是正则表达式的新手,需要弄清楚如何编写它。
批处理结果如下:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
tomcat9.exe 5628 Services 0 1,455,204 K
我看过Regex for number check below a value , Regex for dollar amount greater than $500 , Extracting string from logs with regex in pig script .
我已经尝试了每个建议的答案,但没有得到所需的结果。
服务的内存可能会高于显示的内存。如果它高于 1.8GB,服务将开始无法正确响应。
最佳答案
要匹配 1,800,000
和 999,999,999
之间的任何数字,后跟空格字符,然后是字母 K
,您可以使用:
\b(?:1,[89]|(?:[2-9]|[1-9]\d{1,2}),\d)\d\d,\d{3} K
演示:https://regex101.com/r/H3qaB4/1
分割:
\b # Word boundary.
(?: # Start of a non-capturing group.
1, # Matches `1,` literally.
[89] # Matches 8 or 9 literally.
| # Alternation (OR).
(?: # Start of 2nd non-capturing group.
[2-9] # Matches any digit between 2 and 9.
| # OR..
[1-9] # A digit between 1 and 9.
\d{1,2} # Followed by one or two digits.
) # End of 2nd non-capturing group.
, # Matches `,` literally.
\d # Matches one digit.
) # End of 1st non-capturing group.
\d\d # Matches two digits.
, # Matches `,` literally.
\d{3} # Matches 3 digits.
K # Matches `K` literally.
要使下限为 1,200,000
而不是 1,800,000
,您只需将 [89]
部分替换为 [2- 9]
:
\b(?:1,[2-9]|(?:[2-9]|[1-9]\d{1,2}),\d)\d\d,\d{3} K
关于regex - 如何从批处理输出中检查内存是否大于一定数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55401363/