Thread: Regex examples
View Single Post
Old 06-26-2012, 09:50 AM   #96
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,694
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
<br />'s are not soft-hyphens.... just to be clear.

Quote:
Originally Posted by roger64
Give your songs or poems their own style, keep standard text in its "body text" class and then launch the following Regex...
Tricky... but—strictly speaking of Sigil (PCRE) here—then possibly:

If there's only one occurrence of the <br /> tag inside a paragraph, this expression should find it (only inside p tags of the class "body-text"):
Code:
<p class="body-text">(?!</p>).*\K<br[^>]*?/>
(If there's more than one occurrence of <br /> the above expression will only match the last one)

The following expression should match the first occurrence (if there's more than one) of a <br /> tag inside p tags of the class "body-text".
Code:
(?U)<p class="body-text">(?!</p>).*\K<br[^>]*?/>
Leaving the "Replace" field blank when replacing should then get rid of the <br /> tags.

It's certainly not ideal, but if you have multiple <br /> tags inside the targeted paragraph (class name "body-text"), you could conceivably run one or the other of these "Replace All" expressions multiple times until the search no longer matches anything. Still quicker than stepping through each occurrence (and will ignore all other p classes), though.
DiapDealer is online now   Reply With Quote