Page 1 of 1

Filters: regular expression to match multiple keywords

Posted: 31 Mar 2015, 12:20
by mikkelnl
Hi all,

I'm trying to make a filter that will search feed contents for 3 keywords (all words should be present; AND), but I'm not that great with regular expressions :oops:

I know this functions as 'OR': (keyword1|keyword2|keyword3)

In this example, how could I setup the reg ex so that it will function more like AND instead of OR?

Thanks!

Re: Filters: regular expression to match multiple keywords

Posted: 31 Mar 2015, 12:33
by fox
easiest way: make 3 rules, set to match all

Re: Filters: regular expression to match multiple keywords

Posted: 31 Mar 2015, 12:34
by mikkelnl
fox wrote:easiest way: make 3 rules, set to match all

LOL, I feel like a compleet idiot right now :) Thanks...!

Re: Filters: regular expression to match multiple keywords

Posted: 31 Mar 2015, 19:09
by mikkelnl
Could anyone tell me what the reg ex would be for exact words?

I'd like to avoid triggering content for the word 'Preview' and only have the trigger happen when 'Review' is found. I tried a few expressions but can't get it to work :)

Re: Filters: regular expression to match multiple keywords

Posted: 31 Mar 2015, 19:22
by JustAMacUser
You're looking for word boundaries. So something like:

Code: Select all

\bReview\b


Though I think the backslashes may need to be escaped depending on whether you're using MySQL or PostgreSQL.

Re: Filters: regular expression to match multiple keywords

Posted: 31 Mar 2015, 19:27
by mikkelnl
JustAMacUser wrote:You're looking for word boundaries. So something like:

Code: Select all

\bReview\b


Though I think the backslashes may need to be escaped depending on whether you're using MySQL or PostgreSQL.

Thanks! I tried this but it won't work... could you explain how should I escape backslashes if using MySQL?

Re: Filters: regular expression to match multiple keywords

Posted: 31 Mar 2015, 23:53
by JustAMacUser
I'm going to preface my response with a caveat: The problem is that the "Test" button when configuring a filter operates a bit different than when the filter is actually running so you're going to get different results when you have to escape things. The "Test" button won't necessarily return results even though the filter might work. This is because the Test function actually runs the regular expression as a database query, whereas when the filter is being applied, it runs it against the data collected from a site's feed, but it does this after passing said data through the database escape function.

tl;dr

When escaping characters in a filter the results of Test versus the actual results when the filter is running will be different. Just have faith that you got it right. :)

MySQL uses backslashes for escaping so I'm going to assume what you want is:

Code: Select all

\\bReview\\b


Give it a shot and see how it plays out as feeds are parsed.

Re: Filters: regular expression to match multiple keywords

Posted: 31 Mar 2015, 23:57
by mikkelnl
JustAMacUser wrote:I'm going to preface my response with a caveat: The problem is that the "Test" button when configuring a filter operates a bit different than when the filter is actually running so you're going to get different results when you have to escape things. The "Test" button won't necessarily return results even though the filter might work. This is because the Test function actually runs the regular expression as a database query, whereas when the filter is being applied, it runs it against the data collected from a site's feed, but it does this after passing said data through the database escape function.

tl;dr

When escaping characters in a filter the results of Test versus the actual results when the filter is running will be different. Just have faith that you got it right. :)

MySQL uses backslashes for escaping so I'm going to assume what you want is:

Code: Select all

\\bReview\\b


Give it a shot and see how it plays out as feeds are parsed.

Thanks for the info, had no idea the Test button functions differently ;)

I'll test de new filters the next few days :)