0

I want the version number from the output and for both the output I want one code only

Edition: Read the output starts with Cisco till Version then extract the Version Number

For example:Read the line like this Cisco IOS Software, s2t54 Software (s2t54-ADVIPSERVICESK9-M), Version 15.5(1)SY2, the ouput Version

Output : 15.5(1)SY2

Output 1: ''' Cisco IOS Software, s2t54 Software (s2t54-ADVIPSERVICESK9-M), Version 15.5(1)SY2, RELEASE SOFTWARE (fc6) ROM: System Bootstrap, Version 12.2(50r)SYS3, RELEASE SOFTWARE (fc1) CPU: MPC8572_E, Version: 2.2, (0x80E80022) CORE: E500, Version: 3.0, (0x80210030) '''

Output 2: Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500es8-UNIVERSALK9-M), Version 03.08.07.E RELEASE SOFTWARE (fc2) licensed under the GNU General Public License ("GPL") Version 2.0. The software code licensed under GPL Version 2.0 is free software that comes GPL code under the terms of GPL Version 2.0.

I tried ths code:

r = re.findall(r'Version\s*(([\w]+))', str)
r[0]

it gives output:

15.5

03.08.07.E

expected output:

15.5(1)SY2

03.08.07.E

3 Answers 3

1

Try Version\s+([^,\s]+).+

Explanation:

Version - matches Version literally

\s+ - matches one or more of white spaces

([^,\s]+) - match one or more characters other from whitespace \s or comma , and store it inside first capturing group

.+ - match one or more of any characters (except newline), this is to consume rest of the output and prevent from matching multiple versions in one output

Demo

Sign up to request clarification or add additional context in comments.

Comments

1

I think this is the expression you are looking for:

Version\s*(.+?)[\s|,]

It matches anything after "Version" until it finds a comma or a blank space

Comments

0

I think the best is;

a = r'Version\s*(.+?)[\s|,|[]'

example output:

6.4.2

03.06.06E

03.16.07b.S

12.0(18b)

12.2(33.3.8)SB13

12.2(33)SXI2a

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.