Find and disable/enable users by part of their name

I’ve tried to find and disable user “abc123” by part of his name used this command: /user {:foreach r in=[find user=abc] do={disable $r}}
but it disabled all users except the current admin. Tell me pls, what I do wrong?

is better 1 + 1 + 1 + 1 + 1 + 1 = 6 or 1 * 6 = 6 ?

/user disable [find where name~“abc123”]

EDIT: Thanks @msatter

Perhaps I expressed incorrectly, but the order of the numbers at the end is always different. Just in the example I wrote 123, but actually, there is a different six-digit order of numbers, which is always different on all routers.

@rextended is showing using a regular expression with the "~" instead of "=". That is critical here.

I don't know what your trying to match but

... [find where user~"user[0-9][0-9][0-9][0-9][0-9][0-9]"]

would match anything in the form "userXXXXXX" where each X can be a number 0 to 9.

So if say first three numbers are specific site # like "123", and user-id was last 3 number... adjust like:

... [find where user~"user123[0-9][0-9][0-9]"]

ahummmm, field user does not exits in /users and so all users are iterated:

Correctly using name:

/user> :foreach r in=[find name=test] do={:put "test"}    
test

Incorrectly using user:

/user> :foreach r in=[find user=test] do={:put "test"}    
test
test
test
test
test

If you want to remove disable all users starting with “abc”:

:foreach r in=[find name~"^abc"] do={disable $r}

Thanks @msatter




This match user that start with abc and have a numeric range 0-999999 and also with “0” 000000-099999

# match from abc0 to abc999999 included abc000000-abc099999
/user disable [find where name~"^abc[0-9]{1,6}\$"]

# match only from abc000000-abc999999 do not match from abc0 to abc99999
/user disable [find where name~"^abc[0-9]{6,6}\$"]

Thank y’all so much guys for your answers!
/user disable [find where name~“^abc[0-9]{1,6}$”] - works like charm! :ok_hand: