Replacing quotes with Regex

I’m having a senior moment and need the help of the Regex guru. From plaintext mails I want to replace the quoted part with blockquote tags

[quote]> blabla

some more text

some unquoted text

blubber

some more quoted text[/quote]

should be

[quote]

blabla

some more text

some unquoted text

blubber

some more quoted text

[/quote]

Doing the Regex itself is simple. (^>.(\r|
))+? for the complete quoted text or (^>.
(\r|
)) for a quoted line. But how do I do the replacement?

By repeating three steps.

  1. Identify the block.
  2. Replace “^>\x20*” with “” within that block.
  3. Replace that part of your text with the properly quoted block. (That could be a straight ReplaceAll or you can parse the text yourself.)

To identify the block, try this instead:

(?mi-Us)(^>.*\\R?)+

That pattern specifies greediness with code[/code] and will identify lines at the end of the document. (\\R is the token for “any EOL”.)

If you follow my suggestion, this text:

>Some quote
>>Embedded quote 1
>>Embedded quote 2
>Last line

Should turn into something like this:

<blockquote>Some quote
<blockquote>Embedded quote 1
Embedded quote 2</blockquote>
Last line</blockquote>

And this text:

>>Quote within a quote

Would become this:

<blockquote><blockquote>Quote within a quote</blockquote></blockquote>

Just pointing this out in case you want a different outcome.

Thanks, I’ll try your suggestions.