Separate text with a blank line

It's the end of the year and everyone in Japan is on vacation. Corona infection is still a big problem in Japan, and the internal medicine clinic is busy with many patients.
This year I had the great pleasure of meeting Text Blaze.

Now the electronic medical record I use is chrome based, so TB is a big help. I have only been using it for two weeks, but I think I will continue to use it for the rest of my life.

When I use the electronic chart, I make a copy of the patient's previous visit and paste it into the current chart.

For example.
================
#hypertension
#Hypercholesterolemia
#angina pectoris

No complaint of chest symptoms this time
Blood data is good

etc.

≈================
The first three lines with # are the patient's problem list, i.e., how do I write the code to copy the blank lines up to the point where there is a blank line?

#Hypertension
#Hypercholesterolemia
#angina pectoris

I want to extract, copy and paste only the above.

I have used TB's "Website contents text" to copy the previous medical record.

{chart={site: text; selector=ul > :nth-child(2) section > div}}{=chart}

This can be done without any problem.

Then I tried to extract the first 3 lines with #, separated by blank lines, using a regular expression.
{problem_list=splitregex({=chart}, "^\r\n") }
{=problem_list[1]}

This would copy the entire previous chart, and I think the key is to separate them with a blank line. Any help would be appreciated.

Translated with DeepL Translate: The world's most accurate translator (free version)

Nice idea! Is this what you're looking for?

{chart="#hypertension
#Hypercholesterolemia
#angina pectoris

No complaint of chest symptoms this time
Blood data is good

etc."}
{problems=filter(splitregex(chart, "\n"), line -> startswith(line, "#"))}
{=problems}

If you really want to separate by a blank line, try this:

{chart="#hypertension
#Hypercholesterolemia
#angina pectoris

No complaint of chest symptoms this time
Blood data is good

etc."}
{all_lines=splitregex(chart, "\n")}
{index_of_blank=location(all_lines, "")}
{problems=slice(all_lines, 1, index_of_blank - 1)}
{=problems}

2 Likes

@Gaurang_Tandon
Thank you, I have an additional question.
In this code, the last result is in the form stored in a list, ["#hypertension", "#Hypercholesterolemia", "#angina pectoris"].
How can I write this out in text as follows.
#hypertension
#Hypercholesterolemia
#angina pectoris

This may be basic, but I mean how to write out a list when there are n elements in the list.
In Python or other languages, I suppose I could just use a for statement, but in TB, how can I do that?

The easiest way is to join them with a newline and print them like so:

{problems=["#hypertension", "#Hypercholesterolemia", "#angina pectoris"];trim=yes}
{=join(problems,"\n")}

With a loop, this would be:

{problems=["#hypertension", "#Hypercholesterolemia", "#angina pectoris"];trim=yes}
{repeat: for problem in problems}{=problem}
{endrepeat}

I see you're familiar with the technical details :slight_smile: If you're interested in reading more, check out our formula reference and the {repeat} command.

1 Like

@Gaurang_Tandon Thanks for the quick reply. I see that there is a "repeat" command.

Thanks again , and please have a happy New Year!!

Happy new year to you too :slight_smile: