View Single Post
Old 06-25-2016, 12:29 AM   #1
Psymon
Chief Bohemian Misfit
Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.Psymon ought to be getting tired of karma fortunes by now.
 
Psymon's Avatar
 
Posts: 571
Karma: 462964
Join Date: May 2013
Device: iPad, ADE
Need RegEx help (if it's even at all possible to do!)

Ugh! I don't know the first thing about RegEx, and although it's definitely something I'd love to learn, right now my problem is a little more immediate -- not to mention probably rather complicated (RegEx-wise) -- and I"m really hoping someone can help me out.

I'm working on a book with a few plays of Shakespeare, and have them all nicely coded and stuff. Shakespeare is well known for writing in verse, of course, but many of the characters' lines are also in prose. In that regard, I have two ways of coding up those lines, depending on whether it's in verse or in prose.

I think you should probably be able to see what I've done here, without getting into all the CSS and everything (the only real difference has to do with what happens if/when the line wraps, whether it gets indented or not).

Here's an example of a bit of verse...

Code:
  <p class="speaker">1 Witch</p>

  <p class="verse">When shall we three meet againe?</p>

  <p class="verse">In Thunder, Lightning, or in Raine?</p>
...and here's an example of some prose...

Code:
  <p class="speaker">Hamlet</p>

  <p class="prose">Get thee to a Nunnerie. Why would’st thou be a breeder of Sinners? I am my selfe indifferent honest, but yet I could accuse me of such things, that it were better my Mother had not borne me. I am very prowd, reuengefull, Ambitious, with more offences at my becke, then I haue thoughts to put them in imagination, to giue them shape, or time to acte them in. What should such Fellowes as I do, crawling betweene Heauen and Earth. We are arrant Knaues all, beleeue none of vs. Goe thy wayes to a Nunnery. Where’s your Father?</p>
Now, what I'm trying to accomplish is for if the speaker's line is in verse, then I want to wrap a div around the speaker's name (which is on one line) and that first line of verse, with that div being a CSS class that adds in page-break:avoid.

Does that make sense, what I'm doing, and why I want to do it?

So basically, to use that first example of some verse, it would then look like this...

Code:
  <div class="pageavoid">
    <p class="speaker">1 Witch</p>

    <p class="verse">When ſhall we three meet againe?</p>
  </div>

  <p class="verse">In Thunder, Lightning, or in Raine?</p>
...with that "pageavoid" div wrapped around the "speaker" paragraph and the first "verse" paragraph.

The problem is that I've got almost 3000 of those "speaker" lines -- and each one I would have to actually look at and see if the next line is verse or prose, and either way I then have to add (or not) the "pageavoid" div.

Is there ANY way to do a RegEx search & replace that could do this for me automagically (and save me several days of utter, unbearable drudgery)? Basically, I'd hope that there's a way to search for every instance of a "speaker" paragraph, and then if the next line is a "verse" paragraph, then wrap that "pageavoid" div around them both. Otherwise, if it's a "prose" paragraph, then don't do anything.

I hope I've explained the problem okay, and what it is that I'm trying to accomplish -- and thanks SO much in advance, if this is possible!

Last edited by Psymon; 06-25-2016 at 02:32 AM.
Psymon is offline   Reply With Quote