Help

Need help with REGEX_REPLACE to prepare markdown for HTML formatting

Topic Labels: Formulas
1274 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Neville_Chamber
5 - Automation Enthusiast
5 - Automation Enthusiast

I’m trying to format markdown in a long text field to something I can use in Zapier. The input looks something like this:

# This is a heading 1
This is a paragraph
- bulleted item 1
- bulleted item 2
- bulleted item 3
And here's a paragraph - with an embedded minus, and some more normal text

The output should look like this:

# This is a heading 1

This is a paragraph

- bulleted item 1
- bulleted item 2
- bulleted item 3

And here's a paragraph - with an embedded minus, and some more normal text

In essence, I need to replace the single newline after each paragraph with two newlines, except for the bulleted lists.

My first strategy is to use REGEX_REPLACE(source,“\n”,“\n\n”) which adds the 2 newlines everywhere. So far so good. But for the life of me I can’t find a way to remove the (now) extra newline between the bulleted items (lines starting with a “-”). It seems that the “^” (match at the beginning of a line) in Airtable’s REGEX doesn’t seem to work?

Any suggestions highly appreciated!

3 Replies 3
Neville_Chamber
5 - Automation Enthusiast
5 - Automation Enthusiast

I’ve also tried using

REGEX_REPLACE(source,“\n([^-])”,“\n\n$1”)

which gives me this output:

# Heading 1

And a normal paragraph after that.

And a normal paragraph after that.
- Bullet 1
- Bullet 2
- Bullet 3

And a normal paragraph after that.

And here's a paragraph - with an embedded minus

> And this is a block quote in the middle of it all.

And a paragraph following the blockquote.

## Heading 2

This is some text under the heading 2 - again with a minus embedded.
- And some more content in a bullet
- And another bullet

And some final text

So I’m close, but the first bullet in each case still needs an additional newline above it…

For what it’s worth, using the caret “^” to match a “-” at the start of a line doesn’t seem to work.

I don’t personally know how to do this with REGEX or Zapier, but I personally use Make’s markdown to HTML converter to do this:

Solution found - this consists of 2 formula fields:

step 1: REGEX_REPLACE(source,‘\n([^-])’,‘\n\n$1’) (let’s call this output1)
step 2: REGEX_REPLACE(output1,‘\n([^-])’,‘\n\n$1’)

that does the job. Will post here again if I find exceptions.