I just started to learn programming languages weeks ago. Still a newbie.
I tried the following, but found only the first line (shown below). I would like to learn why if someone can offer an explanation.
So I tried Python instead.
It seems to work.
Here is my code:
# get variable from KM. The variable Var is shown above.
text = os.environ['KMVAR_Var']
# find all lines we want
linesFound = re.findall('(?m)^(fi.*?)$|^(bl.*?)$', text)
The above command will return linesFound = [('fi--this is what I want', ''), ('', 'bl--this is also what I want'), ('fi--this is what I want 2', ''), ('', 'bl--this is also what I want 2')]
So, we have extra work to do. Each element is a list, but one of them has nothing. Below, We just replace the list with the other non-blank string.
for i in range(0, len(linesFound)):
line = "".join(linesFound[i])
linesFound[i] = line
The above loop will return: linesFound = ['fi--this is what I want', 'bl--this is also what I want', 'fi--this is what I want 2', 'bl--this is also what I want 2']
# finally, covert 'linesFound' to a string, with line break added between each line
linesWanted = '\n'.join(linesFound)
fi--this is what I want
bl--this is also what I want
fi--this is what I want 2
bl--this is also what I want 2
I'm also a newbie in AppleScript. I will just give up trying. If you have to use AppleScript, someone else may be able to help.