I'm trying to edit some xhtml on Sigil.

With the command "<p>([a-z]) I'm able to find all paragraphs that begin with lower case. That tells me that they shouldn't be separate from the previous one. It's just a conversion issue.

What should I do to delete both the < p> from that paragraph and the </p> from the previous one in order to join the two blocks of text into one single paragraph??

It looks something like this:

<p> ... that is why relationships</p>

<p> are not what they should be.

And it should be:

<p> that is why relationships are not what they should be.</p>
  • I miss Sigil. I wish it were still being developed.
    – Paulb
    Sep 26, 2015 at 12:34
  • Sigil is being developed. The latest pre-release has some bugs, though..
    – user4665
    Oct 2, 2015 at 5:41
  • What OS are you running Sigil on? Windows?
    – Bulrush
    Jun 28, 2016 at 14:37
  • What OS are you running Sigil on? Windows? All of them. :-) However, it doesn't really matter, because it works the same on all of them.
    – user4665
    Jun 29, 2016 at 21:10

3 Answers 3


The following regex should cover most cases.




\1 \2

Sigil's regex engine is kind of fussy; I'm not sure that the anonymous answer above would work.

I answered this on Quora, but I'll post the answer again here, because it seems like that would be helpful:

Ah. Let me guess. You're converting from a PDF. You have my sympathy. :-)

I've done this. Here's the search expression I used:


That found paragraphs that ended without a period, exclamation point, question mark, or right double quotes. (Since I'm assuming you're working from a PDF of a print document, I didn't include in the query all of the other possible marks, since, for instance, a left double quotation mark is extremely unlikely to come at the end of a text line.)

The replace expression was simply this:


Note that there's a space after the wildcard, so that you don't end up smooshing words together.

That should get rid of the unwanted paragraph breaks and splice your text together properly.

Unfortunately, if you've got letters reproduced in the book or some other text format that has paragraphs ending in commas, semicolons, or lower case letters, you'll have to do Replace/Find and go case by case rather than Replace All.

  • Sigil's regex engine is kind of fussy Sigil uses PCRE, which is pretty much the best RE engine there is. I'm not sure that the anonymous answer above would work. If you were referrring to my suggestion, it does work and unlike your suggestion will only merge broken paragraphs if the next paragraph starts with lower case character.
    – user4665
    Oct 2, 2015 at 5:45
  • The code David Kudler described above on October 2, 2015 has cleaned up hundreds of whitespace problems in ebooks I have been formatting. I love it. But when I stored the code in a folder in OneNote and then pasted it to a new ebook, it stopped working. This was extremely annoying. Perhaps OneNote added some dirty html or whatever. I now store in the code in Notepad++ which has proved to be a better home. It cleans up whitespaces when pasted in from Notepad**. Thanks for contributing the code, David.
    – JimM
    Jan 12, 2023 at 18:40

This worked and you can play with it if you want. Please copy it before changing it. https://regex101.com/r/gO0zG0/1.

A regex replace is like this in Perl: $s=~s/OLDPATTERN/NEWPATTERN/g;

The regex was: /<\/p>\n\n<p>//g;

Replace the first part between the first two // with nothing. The \n SHOULD be properly initialized by the regex engine for your operating system (you shouldn't have to do a thing), because it has different values for different OSes. But if that \n doesn't work, please let me know. You might have to try \l\r or \r\l.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.