#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    8
    Rep Power
    0

    Configuring Regex to find and exxlude words from router text configuration


    Hi guys,

    I have been searching everywhere how to use a Regex in a Netwrok tool that I use from Cisco, the name is Network Compliance Manager.

    I need that the Regex find me the interfaces that the status is down and the running port state is down. So I need to find the configuration text those 2 words, the problem that I have is that some interfaces are in state administratively down and when I use the Regex ^*down.*down.*$ it takes the administratively down interfaces too.

    The config text look like this

    Interface State RunningPortState
    Gigaethernet0/4 down down
    fastethernet1/2 administratively down down
    fasethernet0/2 up up


    So what I need is the regex to match the down down interfaces excluiding the ones that says administratively down, but It looks like imposible for me.

    I hope you guys can help me, appreciatte your help a lot!!!!!!
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    Number down down.
    Code:
    [a-z0-9]+/[0-9] down down
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    8
    Rep Power
    0
    Thanks you very much for your help! I really appreciatte it! Today I tried with this code you send me exactly as you wrote it, but it doesnt work, I dont know why, do you think that this can be a problem in the code? Its there some different way to look for the same with a bit different regex? number down down

    Thank you really much

    Best regards,

    Luisro1
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    8
    Rep Power
    0
    Sorry for the bad information, but today I was checking what is the comand that the tool makes when searching for those regex and the output look like this exactly:

    show ip interface brief
    Interface IP-Address OK? Method Status Protocol
    Vlan1 unassigned YES NVRAM administratively down down
    Vlan30 10.136.1.4 YES NVRAM up up
    FastEthernet1 unassigned YES NVRAM administratively down down





    (I cant upload the image)

    I still need to look for the down down interfaces!!

    Thanks one more time
  8. #5
  9. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    Code:
    (?<!administratively) down down
    might work, if the regex engine supports PCRE syntax.

    Otherwise try the same principle from before of matching what you want rather than not matching what you don't want.

    Four words followed by "down down".
    Code:
    ^[^ ]+ [^ ]+ [^ ]+ [^ ]+ down down$
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    8
    Rep Power
    0
    Thank you very much for your answer!! However didnt work for me, I tried both of them and the 2nd didnt worked at all when I put it tries to find the exact regular expresion so its looking in the configuration text for the pattern ^[^ ]+ [^ ]+ [^ ]+ [^ ]+ down down$ , the first one only searches for the word down that is under the protocol tab of the config text if I modify it like (?<!administratively) down , but when I write it exactly as you wrote it on the asnwer it just doesnt search for anything... I really just dont know what to do now. The only that worked a bit for me was ^*down.*down.*$ but it searches for the admin down interfaces too, do you think that the one that worked a bit can be modified in some way to make it work??

    I know your regex are excellent I think it can be that the Cisco NCM doesnt support some simbols or some regex

    Thanks again buddy

    Regards,

    Luisro1
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    8
    Rep Power
    0
    Man Thanks alot for your help, I made some modifications in the REGEX you sent me and I write it like this ^*(?<!administratively) down.*down.*$ and worked perfectly, I think it was a shot of luck for me! Thanks, really thanks for all your help and time. Needed to do this for today at my job.

    Regards,

    Luisro1
  14. #8
  15. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    Wondering if those spaces between the parts are actually tabs...

    What little I can find about NCM suggests it supports the PCRE syntax I mentioned, so
    Code:
    ^[^ \t]+[ \t]+[^ \t]+[ \t]+[^ \t]+[ \t]+[^ \t]+[ \t]+down[ \t]+down$
    If that works try the shorter and nicer
    Code:
    ^(\S+\s+){4}down\s+down$
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    8
    Rep Power
    0
    Hi requinix,

    Yes I think those spaces are actually tabs, I really appreciatte your dedication and time one more time, that worked perfectly.

IMN logo majestic logo threadwatch logo seochat tools logo