Regex Replacer
The Regex Replacer replaces or removes every part of a field that matches a regular expression. Use it to remove "Read more" lines, tracking links, ads, or to fix the HTML of a source.
Input and output
- Input:
input, any text or HTML field. - Output:
result.
Options
- Regex Pattern: a PHP (PCRE) regular expression, with delimiters, such as
/Read more.*$/i. - Replacement Value: what replaces each match. Leave empty to remove it. Use
$1,$2for the parts captured in brackets.
Examples
| You want | Regex Pattern | Replacement Value |
|---|---|---|
| Remove a sentence | /<p>The post .*? appeared first on .*?<\/p>/is |
(empty) |
| Remove all links but keep their text | /<a[^>]*>(.*?)<\/a>/is |
$1 |
| Use lazy-loaded image addresses | /data-src=/i |
src= |
| Remove empty paragraphs | /<p>(\s\| )*<\/p>/i |
(empty) |
| Turn line breaks into paragraphs | /\n{2,}/ |
</p><p> |
Tips
- The
sflag lets.match line breaks,iignores case,Umakes the quantifiers lazy. - Escape
/inside the pattern as\/, or use another delimiter such as#...#. - Test the pattern on a site such as regex101.com with the PCRE flavour before you add it.
- Add one Regex Replacer for each pattern, and pass each
resultto the next one.