Change multiple blank lines to a single blank line

I always make use of Text Blaze. I am a Japanese internist.

I use TB for electronic medical record entries because my electronic medical record is based on Chrome.

When I am describing an electronic medical record...

#Hypertension
#Diabetes



No change today


Blood test results:.
HDL cholesterol H 87 MG/DL
Neutral fat L 44 MG/DL
HbA1c NGSP H 7.4 %.
Blood glucose 104 MG/DL
LDL cholesterol 107 MG/DL



His BMI is 21.9, and his ideal weight (BMI 22) is 71.3 kg.
Standard weight. Set total daily calorie intake appropriately to maintain or aim for an appropriate weight by limiting total energy intake.

You may have two or more blank lines like this. It looks spaced out and needs to be cleaned up.
We are considering converting this to a single blank line using TB. In other words, I would like to make the above chart entry look as clean as the following.

#Hypertension
#Diabetes

No change today

Blood test results:.
HDL cholesterol H 87 MG/DL
Neutral fat L 44 MG/DL
HbA1c NGSP H 7.4 %.
Blood glucose 104 MG/DL
LDL cholesterol 107 MG/DL

BMI is 21.9 and ideal weight (BMI 22) is 71.3 Kg.
Standard weight. Set your total daily calorie intake appropriately to maintain or aim for an appropriate weight by limiting your total energy intake.

I did this myself.

The chart entry field can be specified with the following code.

{chart={site: text; selector=textarea}}

Put this in the list on every new line

{all_lines=splitregex(chart,"\n")}

I can do this so far, but I can't figure out how to convert multiple blank lines to a single blank line when writing out a new line.

Any help would be appreciated.

{repeat: for (text, i) in all_lines if text <> ""} {=text}.{endrepeat}
This code would eliminate all blank lines, but if only one line is blank, I want to keep it.

Hello again @Naritatsu_Saito ! Interesting question, how about this?

{text="a
b

c

d"}
{=replaceregex(text, "\n{3,}", "\n\n", "sg")}

This will replace any three or more consecutive line breaks with two line breaks, which is effectively one blank new line.

If you do not want any blank lines, you can change it to: {=replaceregex(text, "\n{2,}", "\n", "sg")}

I have used the replaceregex function with the "s" - multiline flag (so I can match newline characters) and the "g" - global flag (so I can find and replace all matches, not just the first match)

1 Like

@Gaurang_Tandon Thanks again.

{note}{text={site: text; selector=textarea}}{endnote}{key: ctrl-a}{key: ctrl-x}{=replaceregex(text, "\n{3,}", "\n\n", "sg")}

The above code works, but there is one problem. The code in the snippet that activates this code sticks, e.g. /blank. How can I remove only this snippet without slowing down the operation?

If you want to remove the shortcut, you can do: {=replace(replaceregex(text, "\n{3,}", "\n\n", "sg"), "/blank", "")}. Would that work for you?

@Gaurang_Tandon
Thank you very much!! It works.