import re
text = 'RANDOM 1 ABBBABBBA SDFSBSBS WBWBSBW WBWBWBWB 10 EBEBEBEB EHRHSHSD EBWBBSHSHSB //'
for between_text in re.findall(r'(?<=RANDOM)(.+?)(?=\/\/)', text):
for word_match in re.findall(r'\b[^\d\W]+\b', between_text):
print(word_match)
Output:
ABBBABBBA
SDFSBSBS
WBWBSBW
WBWBWBWB
EBEBEBEB
EHRHSHSD
EBWBBSHSHSB
(?<=RANDOM)(.+?)(?=\/\/)
:
(?<=RANDOM)
is positive lookbehind, it matches the RANDOM
before the text, (.+?)
matches all the text in between and (?=\/\/)
is positive lookahead, which matches the two \/\/
's. More about (.+?)(?=\/\/)
.
\b[^\d\W]+\b
:
\b
matches word boundaries, and [^\d\W]+
is a negated set that matches digits and non-words (so it matches non-digits, and words); the +
signifies it matches one or more characters.