简体   繁体   English

正则表达式:如何排除一个单词和一个字符?

[英]Regex: How to exclude one word and one character?

I'm working with the Dynamic Disk Monitor in SiteScope and I need a regex that exclude the word "Harddisk" and the character "D". 我正在使用SiteScope中的动态磁盘监视器,并且我需要一个正则表达式,以排除单词“ Harddisk”和字符“ D”。

So far, I found this: 到目前为止,我发现了这一点:

^(?!.*Harddisk).*/percent full

How do I add the part for the exclusion of "D" in the same expression? 如何在同一表达式中添加排除“ D”的部分? I tried this and didn't work: 我尝试了这个,但是没有用:

^(?!.*Harddisk|^D).*/percent full

More details: 更多细节:

This expression brings the percent full of all the Disks that the server has: 该表达式使服务器具有的所有磁盘的充满百分比:

/.*/percent full/

This exclude all the disk that its name start with "Harddisk": 这将排除所有名称以“ Harddisk”开头的磁盘:

/^(?!.*Harddisk).*/percent full/

What I need is to improve the last expression for exclude all the "Hard Disk" and besides, the disk "D". 我需要改进最后一个表达式以排除所有“硬盘”以及磁盘“ D”。

Thank you in advance for your help. 预先感谢您的帮助。

Regards, Estrella. 问候,Estrella。

You can try this: 您可以尝试以下方法:

^(?>[^HD/]++|\BH|H(?!arddisk)|/(?!percent full))+/percent full

(Don't forget to escape the slash if needed) (如果需要,别忘了使用斜杠)

Perhaps the following will be helpful: 也许以下内容会有所帮助:

use strict;
use warnings;

while (<DATA>) {
    print if !/(?=.*\bHarddisk\b)(?=.*\bD\b)/;
}

__DATA__
Harddisk A
disk D
Harddisk D

Output: 输出:

Harddisk A
disk D

The expression evaluated by if has the following form: !(x and y) . if求值的表达式具有以下形式: !(x and y)

把事情简单化。

m{/percent full} && !/\bHarddisk\b/ && !/D/

A coworker helped me and found the answer and I wanted to share it with you: 一位同事帮助了我,找到了答案,我想与您分享:

/^(?!.*[E])^(?!.*(HarddiskVolume)).*/percent full/

I hope this helps. 我希望这有帮助。

Thanks to everyone who answered this! 感谢所有回答此问题的人!

-Estrella -埃斯特雷拉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM