Regex: How to exclude one word and one character?

676 views Asked by At

I'm working with the Dynamic Disk Monitor in SiteScope and I need a regex that exclude the word "Harddisk" and the character "D".

So far, I found this:

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

How do I add the part for the exclusion of "D" in the same expression? 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).*/percent full/

What I need is to improve the last expression for exclude all the "Hard Disk" and besides, the disk "D".

Thank you in advance for your help.

Regards, Estrella.

4

There are 4 answers

0
e.vejar On BEST ANSWER

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

0
Casimir et Hippolyte On

You can try this:

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

(Don't forget to escape the slash if needed)

0
Kenosis On

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).

0
ikegami On

Keep it simple.

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