0
list=[endpoint.av.GrisoftAV.activescan,endpoint.as.KasperskyAS.activescan,
endpoint.fw.ATTFW.description,
endpoint.av["360SafeAV"].activescan,
endpoint.av["H+BEDV"].description]

I need to build a regex to extract the values in third octet

The output needs to be:

GrisoftAV
KasperskyAS
ATTFW
360SafeAV
H+BEDV
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135

2 Answers2

0

You can use the following code:

lst = ['endpoint.av.GrisoftAV.activescan','endpoint.as.KasperskyAS.activescan','endpoint.fw.ATTFW.description','endpoint.av["360SafeAV"].activescan','endpoint.av["H+BEDV"].description']

lst = [re.sub('[.\[\]]', ',', i) for i in lst]
lst = [re.sub('[\"]', '', i) for i in lst]
for i in lst:
    x = i.split(',')
    print x[2]

Here, we're using regex to convert the .[] to commas so that they are easy to split, and we get rid of the quotation inside the strings. Then we split the strings by the comma and retrieve the third elements.

lordingtar
  • 1,042
  • 2
  • 12
  • 29
0

You do not really need regex for this. Standard string manipulations will work just fine.

Code:

def find_octet(a_string):
    return a_string.replace('["', '.').replace('"]', '.').split('.')[2]

Test Code:

list = [
    'endpoint.av.GrisoftAV.activescan',
    'endpoint.as.KasperskyAS.activescan',
    'endpoint.fw.ATTFW.description',
    'endpoint.av["360SafeAV"].activescan',
    'endpoint.av["H+BEDV"].description']

for item in list:
    print(find_octet(item))

Results:

GrisoftAV
KasperskyAS
ATTFW
360SafeAV
H+BEDV
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135