Filters: regular expression to match multiple keywords

Support requests, bug reports, etc. go here. Dedicated servers / VDS hosting only
mikkelnl
Bear Rating Trainee
Bear Rating Trainee
Posts: 15
Joined: 06 Apr 2013, 20:20

Filters: regular expression to match multiple keywords

Postby mikkelnl » 31 Mar 2015, 12:20

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!

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: Filters: regular expression to match multiple keywords

Postby fox » 31 Mar 2015, 12:33

easiest way: make 3 rules, set to match all

mikkelnl
Bear Rating Trainee
Bear Rating Trainee
Posts: 15
Joined: 06 Apr 2013, 20:20

Re: Filters: regular expression to match multiple keywords

Postby mikkelnl » 31 Mar 2015, 12:34

fox wrote:easiest way: make 3 rules, set to match all

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

mikkelnl
Bear Rating Trainee
Bear Rating Trainee
Posts: 15
Joined: 06 Apr 2013, 20:20

Re: Filters: regular expression to match multiple keywords

Postby mikkelnl » 31 Mar 2015, 19:09

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 :)

JustAMacUser
Bear Rating Overlord
Bear Rating Overlord
Posts: 373
Joined: 20 Aug 2013, 23:13

Re: Filters: regular expression to match multiple keywords

Postby JustAMacUser » 31 Mar 2015, 19:22

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.

mikkelnl
Bear Rating Trainee
Bear Rating Trainee
Posts: 15
Joined: 06 Apr 2013, 20:20

Re: Filters: regular expression to match multiple keywords

Postby mikkelnl » 31 Mar 2015, 19:27

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?

JustAMacUser
Bear Rating Overlord
Bear Rating Overlord
Posts: 373
Joined: 20 Aug 2013, 23:13

Re: Filters: regular expression to match multiple keywords

Postby JustAMacUser » 31 Mar 2015, 23:53

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.

mikkelnl
Bear Rating Trainee
Bear Rating Trainee
Posts: 15
Joined: 06 Apr 2013, 20:20

Re: Filters: regular expression to match multiple keywords

Postby mikkelnl » 31 Mar 2015, 23:57

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 :)


Return to “Support”

Who is online

Users browsing this forum: No registered users and 6 guests