Negating a regex

(imported topic written by SystemAdmin)

Hi all,

Hope kind soul can help me with this - I’m trying to get all the lines of a file that don’t match a particular string construct. My input file is from the /etc/passwd file (cut down) and has the following:-

root:x

uatapache:x

u1234:x

lnadmin:x

n567890:x

I can pull all the accounts that start with a ‘u’ or a ‘n’ and are followed by three to eight numerals using:-

((parenthesized part 1 of it) of matches (regex "^([un][0-9]{3,8}):.+$") of (it as lowercase)) of lines of file "passwd.mw"

which returns:

u1234

n567890

What is the correct syntax for the regex to return all the lines that

don’t

match the above criteria? i.e. -

root

uatapache

lnadmin

Is it even possible?

Thanks,

Mark.

(imported comment written by NoahSalzman)

There are a number of different ways to do it.

This is one approach:

Q: exists matches (regex “bar”) of “foo”

A: False

Q: exists matches (regex “foo”) of “foo”

A: True

If you want to use negation in the regex then it would look like this:

Q: exists matches (regex “foo”) of “foo”

A: True

Q: exists matches (regex "

^foo

") of “foo”

A: False

Another way is to have the regex return the name of the user and do something like:

it is not “root” OR it is not “uatapache” OR it is not “lnadmin”

Lastly, if your “is not” set is quite large then – so simplify the syntax – you can create a list and use Relevance’s set logic to see if each user name is in the list.

(imported comment written by SystemAdmin)

Hi Noah,

While I was reading your response I had an epiphany - I was asking the wrong question!

What I really wanted was all the lines that start with

any

character but don’t have 3 to 8 numerics beginning at position 2.

The following got me the results I was after…

regex "^(.[^0-9]{3,8}):.+$"

Thanks,

Mark.