Oh great and wise monks,

I have been working on a couple of example uses for perl in the humanities. See this node for some background information. I have run into a problem however that I hope you can help me solve.

I was going to show them how to parse up some of the information in the Annals of Ulster. For example,

U448.1\n \n Several walls of the imperial city of Constantinople which had been fr +eshly\n rebuilt with masonry, and fifty-seven towers collapsed as a result of +a\n violent earthquake which prevailed in various places.\n \n U483.2\n \n Or, this year the battle of Ocha according to others, won by Muirchert +ach\n Mac Erca and by Fergus Cerball son of Conall of Cremthann, and by Fiac +hra\n Lon son of the king of Dal nAraide.\n \n

Now as you can see, it always starts with the letter 'U', which is a good thing to anchor the regex. Then it has two \n another good solid thing. Then I run into problems because the lines of text for a paragraph are broken up by single \n then it ends with two \n. So I come up with a regex something like this:

/U(\d+\.\d+)\n{2}(.+)\n{2}/

The problem is that if I use the regex modifier /s it is completely greedy and matches everything rather than just things between the two \n\n delimiters. What I would like is a regex that matches multiple lines including single \n but stops when it gets to \n\n. I am sure that I am missing something simple but I cannot think of it right now and humbily beseech your wisdom on the topic.


In reply to Regex Question by cyocum

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.