Regular expression used in Exscript prompt - understanding existing one or creating a custom one

151 Views Asked by At

I am having trouble with understanding this regular expression that exscript is using to detect the prompt for an NX-OS switch

'[\\\\r\\\\n][\\\\-\\\\w+\\\\.:/]+(?:\\\\([^\\\\)]+\\\\))?[>#] ?$'

This is Python

My prompt should be something like a string of any number of alpha numeric characters that ends with '#'

I tried '^.*#' but it did not work. There is no spaces or - in the string

Edit

For your fan here are a couple of other similar regex used in the login process to recognize various prompts that the remote OS can send back

generic: waiting for: ['[\\r\\n][^\\r\\n]*(?:bad secrets|denied|invalid|too short|incorrect|connection timed out|failed|failure)', '(user ?name|user|login): *$', '(?:s\\/key|otp-md4) (\\d+) (\\S+)(?=\\s|[\\r\\n])', 'password:? *$', '[\\r\\n](?:[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\!\\"\\#\\$\\%\\&\\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\ \\\t\\\n\\\r\\\x0b\\\x0c]*|[\\x1b\\x07\\x00]*)[\\[\\<]?\\w+(?:(?:(?:[\\w+\\-]+)\\@)?(?:[\\w+\\-\\.]+))?:?(?:(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)|~(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)?)?[: ]?(?:(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)|~(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)?)?(?:\\((?:[\\w\\+\\-\\._]+)\\))?[\\]\\-]?[#>%\\$\\]] ?[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\!\\"\\#\\$\\%\\&\\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\ \\\t\\\n\\\r\\\x0b\\\x0c]*\\Z']
generic: Expecting a prompt
generic: Expected pattern: ["'[\\\\r\\\\n][^\\\\r\\\\n]*(?:bad secrets|denied|invalid|too short|incorrect|connection timed out|failed|failure)'", "'(user ?name|user|login): *$'", "'(?:s\\\\/key|otp-md4) (\\\\d+) (\\\\S+)(?=\\\\s|[\\\\r\\\\n])'", "'password:? *$'", '\'[\\\\r\\\\n](?:[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\\\!\\\\"\\\\#\\\\$\\\\%\\\\&\\\\\\\'\\\\(\\\\)\\\\*\\\\+\\\\,\\\\-\\\\.\\\\/\\\\:\\\\;\\\\<\\\\=\\\\>\\\\?\\\\@\\\\[\\\\\\\\\\\\]\\\\^\\\\_\\\\`\\\\{\\\\|\\\\}\\\\~\\\\ \\\\\\t\\\\\\n\\\\\\r\\\\\\x0b\\\\\\x0c]*|[\\\\x1b\\\\x07\\\\x00]*)[\\\\[\\\\<]?\\\\w+(?:(?:(?:[\\\\w+\\\\-]+)\\\\@)?(?:[\\\\w+\\\\-\\\\.]+))?:?(?:(?:(?:(?:[\\\\w\\\\+\\\\-\\\\._]+))?(?:/(?:[\\\\w\\\\+\\\\-\\\\._]+))*/?)|~(?:(?:(?:[\\\\w\\\\+\\\\-\\\\._]+))?(?:/(?:[\\\\w\\\\+\\\\-\\\\._]+))*/?)?)?[: ]?(?:(?:(?:(?:[\\\\w\\\\+\\\\-\\\\._]+))?(?:/(?:[\\\\w\\\\+\\\\-\\\\._]+))*/?)|~(?:(?:(?:[\\\\w\\\\+\\\\-\\\\._]+))?(?:/(?:[\\\\w\\\\+\\\\-\\\\._]+))*/?)?)?(?:\\\\((?:[\\\\w\\\\+\\\\-\\\\._]+)\\\\))?[\\\\]\\\\-]?[#>%\\\\$\\\\]] ?[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\\\!\\\\"\\\\#\\\\$\\\\%\\\\&\\\\\\\'\\\\(\\\\)\\\\*\\\\+\\\\,\\\\-\\\\.\\\\/\\\\:\\\\;\\\\<\\\\=\\\\>\\\\?\\\\@\\\\[\\\\\\\\\\\\]\\\\^\\\\_\\\\`\\\\{\\\\|\\\\}\\\\~\\\\ \\\\\\t\\\\\\n\\\\\\r\\\\\\x0b\\\\\\x0c]*\\\\Z\'']
generic: Shell prompt received.
generic: Calling driver.auto_authorize().
generic: Attempting to app-authorize usernaem.
generic: waiting for: ['[\\r\\n][^\\r\\n]*(?:bad secrets|denied|invalid|too short|incorrect|connection timed out|failed|failure)', '(user ?name|user|login): *$', '(?:s\\/key|otp-md4) (\\d+) (\\S+)(?=\\s|[\\r\\n])', 'password:? *$', '[\\r\\n](?:[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\!\\"\\#\\$\\%\\&\\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\ \\\t\\\n\\\r\\\x0b\\\x0c]*|[\\x1b\\x07\\x00]*)[\\[\\<]?\\w+(?:(?:(?:[\\w+\\-]+)\\@)?(?:[\\w+\\-\\.]+))?:?(?:(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)|~(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)?)?[: ]?(?:(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)|~(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)?)?(?:\\((?:[\\w\\+\\-\\._]+)\\))?[\\]\\-]?[#>%\\$\\]] ?[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\!\\"\\#\\$\\%\\&\\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\ \\\t\\\n\\\r\\\x0b\\\x0c]*\\Z']
generic: Expecting a prompt
generic: Expected pattern: ["'[\\\\r\\\\n][^\\\\r\\\\n]*(?:bad secrets|denied|invalid|too short|incorrect|connection timed out|failed|failure)'", "'(user ?name|user|login): *$'", "'(?:s\\\\/key|otp-md4) (\\\\d+) (\\\\S+)(?=\\\\s|[\\\\r\\\\n])'", "'password:? *$'", '\'[\\\\r\\\\n](?:[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\\\!\\\\"\\\\#\\\\$\\\\%\\\\&\\\\\\\'\\\\(\\\\)\\\\*\\\\+\\\\,\\\\-\\\\.\\\\/\\\\:\\\\;\\\\<\\\\=\\\\>\\\\?\\\\@\\\\[\\\\\\\\\\\\]\\\\^\\\\_\\\\`\\\\{\\\\|\\\\}\\\\~\\\\ \\\\\\t\\\\\\n\\\\\\r\\\\\\x0b\\\\\\x0c]*|[\\\\x1b\\\\x07\\\\x00]*)[\\\\[\\\\<]?\\\\w+(?:(?:(?:[\\\\w+\\\\-]+)\\\\@)?(?:[\\\\w+\\\\-\\\\.]+))?:?(?:(?:(?:(?:[\\\\w\\\\+\\\\-\\\\._]+))?(?:/(?:[\\\\w\\\\+\\\\-\\\\._]+))*/?)|~(?:(?:(?:[\\\\w\\\\+\\\\-\\\\._]+))?(?:/(?:[\\\\w\\\\+\\\\-\\\\._]+))*/?)?)?[: ]?(?:(?:(?:(?:[\\\\w\\\\+\\\\-\\\\._]+))?(?:/(?:[\\\\w\\\\+\\\\-\\\\._]+))*/?)|~(?:(?:(?:[\\\\w\\\\+\\\\-\\\\._]+))?(?:/(?:[\\\\w\\\\+\\\\-\\\\._]+))*/?)?)?(?:\\\\((?:[\\\\w\\\\+\\\\-\\\\._]+)\\\\))?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