0

Had two inputs based on the device it need to match any of input using Or and give the version output like 7.0.3I4.6 or 7.1.4.N1.1

Input-1 NXOS image file is: bootflash:///nxos.7.0.3.I4.6.bin

Input-2 kickstart image file is: bootflash:///n6000-uk9-kickstart.7.1.4.N1.1.bin system image file is: bootflash:///n6000-uk9.7.1.4.N1.1.bin

Please suggest how to filter using Or and regular expression

Tried

regex_version = re.compile(r'(NXOS:\sversion\s(\S+))|(kickstart:\sversion\s(\S+))')

version = regex_version.findall(input)

Tried

regex_version = re.compile(r'(NXOS:\sversion\s(\S+))|(kickstart:\sversion\s(\S+))')

version = regex_version.findall(input)

output: [('NXOS: version 7.0(3)I4(6)', '7.0(3)I4(6)', '', '')] [('', '', 'kickstart: version 7.1(4)N1(1)', '7.1(4)N1(1)')]

how to filter 7.0(3)I4(6) and 7.1(4)N1(1) based on the input

Alec
  • 8,529
  • 8
  • 37
  • 63
naruto
  • 53
  • 7
  • Try: `regex_version = re.compile(r'(NXOS:\sversion\s(\S+)|kickstart:\sversion\s(\S+))')` (the `|` must be in a group `()` – Perplexabot May 16 '19 at 00:57
  • 2
    Possible duplicate of [Python regular expressions OR](https://stackoverflow.com/questions/8609597/python-regular-expressions-or) – Perplexabot May 16 '19 at 00:58

1 Answers1

1

This is really simple with the | (OR) operator:

regex_version = re.compile(r'(NXOS:\sversion\s(\S+)|kickstart:\sversion\s(\S+))')

The key is that the OR operator goes between the two terms with no delimiting parentheses or brackets

Alec
  • 8,529
  • 8
  • 37
  • 63
  • tried that i am getting output as below [('NXOS: version 7.0(3)I4(6)', '7.0(3)I4(6)', '')] [('kickstart: version 7.1(4)N1(1)', '', '7.1(4)N1(1)')] – naruto May 18 '19 at 19:02