Home > Back-end >  Looking for users in Cisco configuration
Looking for users in Cisco configuration

Time:11-18

I need to get an expression to get users in cisco which has not lower privileges 0 or 1. Users can be found in configuration file in the following way:

username myuser privilege 15 password 7 5345345345

So, I´m trying with expression:

(username.*privilege )(?!([01]))( password 7)

To get all lines with "username privilege" for any user name, followed by a group of characters that aren´t 0 or 1, and followed by "password" and other characters.

But testing in some online tester webpage i am not receiving the desired result. what am i doing wrong?

Thanks a lot

CodePudding user response:

You can add a word boundary after [01]\b and when that assertion is true, you could still have to match the digits using [0-9]

The pattern matches password 7 literally, but you could also use [0-9] here to match the digits.

.*\b(username.*privilege) (?![01]\b)[0-9]  (password [0-9] ).*

Regex demo

Note that if you only want to match the whole line, you can omit the capture groups:

.*\busername.*?privilege (?![01]\b)[0-9]  password [0-9].*
  • Related