How Do I Find Multiple Occurences Of This Specific String And Split Them Into A List?
I'm trying to find a specific piece of string inside a bigger whole of a string. Here's the string, and the bold words are the ones that i want to extract using the re.findall func
Solution 1:
re.findall('[^|]+(?=\|\@\|)', doc)
Explanation:
[^|]+
finds chunks of text not containing the separator(?=...)
is a "lookahead assertion" (match the text but do not include in result)
Solution 2:
This is a dirty solution, but works was on top of my head:
import re
s = "text|p1_1_SNtestfilefri01|ANTENNA SYSTEM|@|text|p1_2_SNtestfilefri01|ALCATEL-LUCENT|@|text|p1_3_SNtestfilefri01|MW ANTENNA|@|text|p1_4_SNtestfilefri01|DIA 0.6 M 13 GHZ SINGLE POLARIZED|@|text|p1_5_SNtestfilefri01|L1AF10018AAAA|@|"
s = s.split('@')
match_list = []
fordatain s:
data += "@|"
m = re.search('\|(.*)\|(.*)\|\@\|', data)
if m:
match_list.append(m.group(2))
Post a Comment for "How Do I Find Multiple Occurences Of This Specific String And Split Them Into A List?"