
David A. Desrosiers wrote:
On Tue, Sep 8, 2009 at 6:07 PM, Marcello Perathoner<marcello@perathoner.de> wrote:
But no way to decide which ones to drop and which one to keep.
Given the previous example, negative lookahead assertions seem to fit well here:
s/(?<!\n)\n(?!\n)/.../g or perhaps ^\n(?!\n) if you need to anchor it or /\n(?!\n)/ for zero width and /\n[^\n]/ for width=1 and so on.
Plenty of ways to skin that cat in most regex-capable languages.
ROTFL! Apply that algorithm to Hamlet and see. See if you can come up with an algorithm that doesn't make mincemeat of the following small excerpt. The algorithm should at least: 1. Recognizes that "HAMLET, PRINCE OF DENMARK by William Shakespeare" is the title statement of the work. This should be marked up like: <h1>Hamlet, Prince of Denmark<br/><br/> by William Shakespeare</h1> and NOT: <h1>Hamlet, Prince of Denmark</h1> <h2>by William Shakespeare</h2> 2. Not wrap the list of persons proper, BUT wrap <p>Lords, Ladies, Officers, Soldiers, Sailors, Messengers, and other Attendants.</p> 3. Recognize that <p>SCENE. Elsinore</p> is a stage direction, not the start of scene 1. 4. Recognize <h2>ACT I.</h2> 5. Recognize <h3>Scene I. Elsinore. A platform before the Castle.</h3> (Even if it lacks spacing.) --- start excerpt from #1524 ---- HAMLET, PRINCE OF DENMARK by William Shakespeare PERSONS REPRESENTED. Claudius, King of Denmark. Hamlet, Son to the former, and Nephew to the present King. Polonius, Lord Chamberlain. Horatio, Friend to Hamlet. Laertes, Son to Polonius. Voltimand, Courtier. Cornelius, Courtier. Rosencrantz, Courtier. Guildenstern, Courtier. Osric, Courtier. A Gentleman, Courtier. A Priest. Marcellus, Officer. Bernardo, Officer. Francisco, a Soldier Reynaldo, Servant to Polonius. Players. Two Clowns, Grave-diggers. Fortinbras, Prince of Norway. A Captain. English Ambassadors. Ghost of Hamlet's Father. Gertrude, Queen of Denmark, and Mother of Hamlet. Ophelia, Daughter to Polonius. Lords, Ladies, Officers, Soldiers, Sailors, Messengers, and other Attendants. SCENE. Elsinore. ACT I. Scene I. Elsinore. A platform before the Castle. [Francisco at his post. Enter to him Bernardo.] Ber. Who's there? Fran. Nay, answer me: stand, and unfold yourself. Ber. Long live the king! Fran. Bernardo? Ber. He. Fran. You come most carefully upon your hour. --- end excerpt #1524 ---- -- Marcello Perathoner webmaster@gutenberg.org