Regular Expression Reference

RegexBuddy is a great tool for working with these regular expressions.

Remove Consecutive Duplicate Lines

This regular expression will match a sequence of lines that are identical. The replace pattern will replace all those matched lines with just the first instance of that line (i.e., it will remove duplicates).

Match Pattern

(?<LINE>((?!\r|\n).)+)(\r\n\k<LINE>)+(?=\r\n|$)

Replace Pattern

${LINE}

Sample Input

No beer
and no TV
make Homer
something
something

Sample Output

No beer
and no TV
make Homer
something

Match a Single Paragraph Only

This regular expression will match rich text containing exactly one paragraph. Multiple paragraph tags will not match. Useful if you want to allow the content editor to use a rich text editor, but want to restrict them to a single paragraph.

Match Pattern

^<p>((?!<p>).)+$

Sample Input

<p>I am <strong>a single</strong> paragraph.</p>