Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with re.findall
#9
(Oct-20-2018, 05:57 AM)alinaveed786 Wrote: I was able to achieve via below modifications. Thanks everyone for all the help and support

#!/usr/bin/python

import re
import subprocess


s = subprocess.check_output(["opatch", "lsinventory"])
output = s.decode("utf-8")


patches = [27923320, 27547329, 21463894, 12345, 99999]

patches_found = set(re.findall(r'\b(?:%s)\b' % '|'.join(map(str, patches)), output))
patches_missing = set(map(str, patches)) - patches_found

if patches_found:
    print('Patch', patches_found, "detected")

if patches_missing:
    print("Patch", patches_missing, "missing")
    

You convert patches elements to strings twice - would not it have been easier to just define them as strings?!
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
Issue with re.findall - by alinaveed786 - Oct-18-2018, 10:44 AM
RE: Issue with re.findall - by buran - Oct-18-2018, 10:53 AM
RE: Issue with re.findall - by alinaveed786 - Oct-18-2018, 10:55 AM
RE: Issue with re.findall - by buran - Oct-18-2018, 11:13 AM
RE: Issue with re.findall - by alinaveed786 - Oct-18-2018, 11:58 AM
RE: Issue with re.findall - by ichabod801 - Oct-18-2018, 01:07 PM
RE: Issue with re.findall - by buran - Oct-18-2018, 01:26 PM
RE: Issue with re.findall - by alinaveed786 - Oct-20-2018, 05:57 AM
RE: Issue with re.findall - by volcano63 - Oct-20-2018, 09:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  regex findall() returning weird result Radical 1 678 Oct-15-2023, 08:47 PM
Last Post: snippsat
  Python: re.findall to find multiple instances don't work but search worked Secret 1 1,241 Aug-30-2022, 08:40 PM
Last Post: deanhystad
  regex.findall that won't match anything xiaobai97 1 2,057 Sep-24-2020, 02:02 PM
Last Post: DeaD_EyE
  Regex findall() NewBeie 2 4,330 Jul-10-2020, 12:19 PM
Last Post: DeaD_EyE
  re.findall HELP!!! only returns None Rusty 10 7,085 Jun-20-2020, 12:13 AM
Last Post: Rusty
  The "FindAll" Error BadWhite 6 4,461 Apr-11-2020, 05:59 PM
Last Post: snippsat
  Beginner question: lxml's findall in an xml namespace aecklers 0 2,948 Jan-22-2020, 10:53 AM
Last Post: aecklers
  [Regex] Findall returns wrong number of hits Winfried 8 5,883 Aug-23-2018, 02:21 PM
Last Post: Winfried
  Combining the regex into single findall syoung 0 2,544 May-28-2018, 10:11 AM
Last Post: syoung
  unable to print the list when using re.findall() satyaneel 5 4,182 Sep-27-2017, 10:26 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020