RSS Guard filter: Modify news item title

A filter for RSS Guard that will match specific text patterns in a news item title, and replace what is matched with something else.

In case you aren’t that familiar with regular expressions, here’s what the sample line

 msg.title = msg.title.replace(/(Italy)/, '🇮🇹$1');

does. For a start, just replace Italy and the emoji with your own choices (you can also add a whole sequence of lines like this). Expand your filters later, as you are getting more and more familiar with regular expressions.

  • /(Italy)/ will simply match the word »Italy«. Lowercase and uppercase matter, so the filter will not react to »italy«, for instance.
  • The round brackets () around a keyword like Italy allow us to refer to the group of characters that have been matched, by the number of that character group. Since there is only one pair of round brackets, there is also only one group we can refer to, the group number 1. We can refer to it by writing $1.
  • Therefore, the whole line means: search for an occurrence of the character group »Italy«, and if you find it, replace it by the Italian flag, followed by that character group, which results in »Italy« being replaced by »🇮🇹Italy«.

Read RSS Guard feed filtering: Easier skimming, better overview for some more complex examples you might like to try.

To copy this filter into RSS Guard, first hover with your mouse over the listing below and press »Open code in new window«. Copying the colored and formatted listing below, as-is, won’t work.
function filterMessage() {
  /* Add your title modifiers here: */

  msg.title = msg.title.replace(/(Italy)/, '🇮🇹$1');
  


  /* Ignore from here, unless you're a developer: */

  /* Remove repeated emojis */

  msg.title = msg.title.replace(
      /([\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]|\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]){1,}/g,
      '$1');


  return MessageObject.Accept;
}

Image Credits:
Papirus icon for RSS Guard (modified) | GNU General Public License, version 3

Licensing:
This content is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
For your attributions to us please use the word »tuxwise«, and the link https://tuxwise.net.