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

lloyd <>
Sun Dec 25 03:52:17 CET 2016

Thanks all, but apologies.

I misstated my problem. 

What I'm really need to do is convert:

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


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

Such that:

   length(MyString) returns 3
   [length(String) || String <- MyString] returns [N1, N2,N3]

re and string:tokens/2 got a bit muddled in my mind.

Thanks again,


-----Original Message-----
From: "Kenneth Lakin" <>
Sent: Saturday, December 24, 2016 5:42pm
To: , "Lloyd R. Prentice" <>
Subject: Re: [erlang-questions] How can I break this string into a list of strings?

On 12/24/2016 01:34 PM,  wrote:
> I don't want those pesky escaped quotes at the end of the heads. I want the real deal. 

Does it help you to know that those double-quotes aren't _actually_
escaped and that the backslashes are added by the pretty-print code?
Continuing on with your example:

2> B=re:replace(Copy, [$>,$\n], [$>,$",$,,$"], [global, {return, list}]).
%re:replace output elided
3> lists:nth(16, B).
4> lists:nth(15, B).

ASCII 34 is '"'. ASCII 62 is '>'. There's no "\" in the output, which
would be ASCII 92:

5> lists:foldl(fun(92, Acc) -> Acc ++ [92]; (_, Acc) -> Acc end, [], B).

The pretty-printer is a nice feature (AFAICT, anything the
pretty-printer prints is valid Erlang), but I suspect that being
startled by its escaping is a rite of passage.

More information about the erlang-questions mailing list