Bigfix and REGEX

I am trying to use REGEX to locate all computers that have the pattern SQL in the name. The pattern can be more towards the beginning or towards the end of the name and it contains numbers also. I have the following relevance but does not seem correct because if I run it locally on a system with a name like cstfmrdevsqlb04 I would think that it would evaluate to true but it comes back as false.

exists matches (regex “[SQL*]+(\d+)+[A-Za-z]+(\d+)”) of computer name

Can someone let me know what I seem to be missing here to get this to work.

Can’t you use the operator contains ?

computer name contains "SQL"
1 Like

You can absolutely use “contains”, but I’d recommend adding lowercase or uppercase operators to ensure validity of string comparison.

computer name as lowercase contains "SQL" as lowercase

1 Like

I agree with the earlier comments that you should just use computer name as lowercase contains "sql".

That said, a little explanation on how your regex appears to parse to me -

regex "[SQL*]+(\d+)+[A-Za-z]+(\d+)
[SQL*]+
The characaters “S”, “Q”, “L”, or “*”, at least one occurrence.
-> Lowercase “s”,“q”, or “l” do not match.
-> Does not require all three characters, or their order, so any “S” such as “SEC” would also match

(\d+)+ - at least one digit, up to any number of digits. The two “+” are redundant.
[A-za-z]+ - at least one alpha character, up to any number of alpha characters
(\d+) - at least one digit, up to any number of digits

So, “cstfmrdevsqlb04” fails in several ways -

  1. The “sql” is not uppercase
  2. The “sql” is not followed by a digit, then an alpha, then another digit (it’s followed by the “b” character, with a digit after)

A computername that matches the regex would be something like

q: exists matches (regex "[SQL*]+(\d+)+[A-Za-z]+(\d+)") of "cstfmrdevSQL04b1"
A: True

If you wanted to only have the condition “must contain SQL” that is much more easily done as in the other comments, but a Regex to match would be something like one of the following:

q: exists matches (regex "[Ss][Qq][Ll]") of "cstfmrdevsqlb04"
A: True
T: 0.110 ms

q: exists matches (case insensitive regex "SQL") of "cstfmrdevsqlb04"
A: True
T: 0.122 ms

The first is for exactly one of “S” or “s”, followed by exactly one of “Q” or “q”, followed by exactly one of “L” or “l”. The second switches to “case insenstive regex” to just look for “SQL” in order, upper- or lower-case.

1 Like

Jason,

Thanks for the explanation and will make the changes. This is exactly what I needed.