[erlang-questions] How can I break this string into a list of strings?

lloyd <>
Sat Dec 24 22:34:22 CET 2016


A naive question. 

But every time I look into the re module my heart starts pounding. I spend uncountable time figuring out what I need to do. But this time I failed.

Suppose I have the following string:

    "<h1>Hello!</h1>\n     <h2>How are you?</h2>\n    <p>Some text\n and more text.</p>"

I would like to break it into a list:

    ["<h1>Hello!</h1>", "<h2>How are you?</h2>", "<p>Some text\n and more text.</p>"]

string:token(MyString, "$\n") doesn't work because it would break the paragraph. 

So I try:

    re:replace(Copy, [$>,$\n], [$>,$",$,,$"], [global, {return, list}]).

But I get:

   "<h1>Hello!</h1>\",\"     <h2>How are you?</h2>\",\"    <p>This is....

I don't want those pesky escaped quotes at the end of the heads. I want the real deal. 

But how can I make it happen?

Thanks and holiday cheer to all,


More information about the erlang-questions mailing list