I am writing a python script and would like to match all Group object name from a large file, an example of the raw data as below:
IT_PC (Group) -Host: 192.168.103.144 -Host: 192.168.103.145 -Network: 192.168.103.0 255.255.255.0 HR_PC (Group) -Host: 192.168.65.145 -Host: 192.168.62.146 -Host: 192.168.62.154
Finance_PC (Group) -Finance_PC_192.168.41.125
Testing_PC (Group) -Host: 192.168.129.1 -Host: 192.168.129.97 -Host: 192.168.59.81 -Host: 192.168.59.82
My required output shall be like this:
IT_PC (Group)
HR_PC (Group)
Finance_PC (Group)
Testing_PC (Group)
I am trying to use below regular express to match my required result but it only return the first one ['IT_PC (Group)']. Is there any advice for me thanks.
source = "IT_PC (Group) -Host: 192.168.103.144 -Host: 192.168.103.145 -Network: 192.168.103.0 255.255.255.0 HR_PC (Group) -Host: 192.168.65.145 -Host: 192.168.62.146 -Host: 192.168.62.154 Finance_PC (Group) -Finance_PC_192.168.41.125 Testing_PC (Group) -Host: 192.168.129.1 -Host: 192.168.129.97 -Host: 192.168.59.81 -Host: 192.168.59.82"
data = ".*? (?= \(group\))"
a = re.findall(data, source)
print a