regex - 如何从批处理输出中检查内存是否大于一定数量?

标签 regex batch-file

我有一个批处理文件,它从远程服务器提取信息并显示我的一项服务的信息。

我使用的批处理如下:

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,000999,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

演示:https://regex101.com/r/H3qaB4/2

关于regex - 如何从批处理输出中检查内存是否大于一定数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55401363/

相关文章:

php - MySql按月、按周的时间戳查询及比较

regex - 正则表达式: how to deal with character/

file - 将文件 move 到另一个目录的批处理文件

PHP/MySQL 批量删除

regex - 增加字符串中所有遵循某种模式的术语的数量

java - 正则表达式语句(replaceAll)

batch-file - if 语句不工作批处理(直接转到 else)

batch-file - 通过批处理文件远程启动 UFT ( QTP ) 测试。

regex - 为什么无法使用正则表达式解析 HTML/XML : a formal explanation in layman's terms

batch-file - 如何防止 Robocopy 处理空的顶级目录?