I have a stream of structured strings. I want to extract 2 specific sections from each of them in Python language.
For example) my Strings are looking like these:
cpe:2.3:a:troglobit:uftpd:*:*:*:*:*:*:*:*
cpe:2.3:o:google:android:8.0:*:*:*:*:*:*:*
cpe:2.3:a:microsoft:asp.net_core:2.1:*:*:*:*:*:*
I need the BOLD sections only.
Be aware that in the end the number of * is different in each case (it's between 6,7,8). Also, the strings could be started by cpe:2.3:o: or cpe:2.3:a:
I have tried different expressions such as these:
For example, this one works with cases that only have 6 * at the end.
try:
temp = re.search("cpe:2.3:a:(.*):\*:\*:\*:\*:\*:\*",testString).group(1)
except AttributeError:
temp = 'NOT FOUND'
Or
(Does not work)
try:
temp = re.search("(cpe:2.3:a:(.*)|cpe:2.3:o:)(.*)(:\*:\*:\*:\*:\*:\*:\*:\*|:\*:\*:\*:\*:\*:\*:\*|:\*:\*:\*:\*:\*:\*)", testString).group(1)
except AttributeError:
temp = 'NOT FOUND'
Or
(Does not work)
try:
temp = re.search("(cpe:2.3:a:(.*):(.*))':{0}'$", testString).group(1)
except AttributeError:
temp = 'NOT FOUND'
Thank You.