Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7953995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:17:29+00:00 2026-06-04T03:17:29+00:00

It’s quite difficult to describe (especially as a non-native speaker), but I’ll do my

  • 0

It’s quite difficult to describe (especially as a non-native speaker), but I’ll do my best:

In my python program, I have a database of, let’s say, news articles and one of the users wanting to be informed about a subset of them.
Every news object has multiple strings like Author, Title or Text.

I want to save the user’s interests as an expression which allows me to match the different string attributes and combine those matches with logical operators like this (The syntax doesn’t really matter):

attribute author matches pattern (\w*\sSmith) and attribute text doesn't
contain pattern (financ(e|ial))

Then, I have to iterate, for every user, over all articles and if the expression is valid, inform him/her.

My problem is that I don’t really know what language to use. I’d like to avoid creating my own and writing my own parser with all the usual problems (security, escaping, etc.) because I’m sure this is a fairly common problem and there has to be a better solution than I’m able to create.

I’ve searched the web for some time now, but haven’t found anything. Every help is very appreciated; thanks in advance!

[Edit:] Reformat pseudo-code as RabbidRabbit suggested.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:17:30+00:00Added an answer on June 4, 2026 at 3:17 am

    There are several ways to approach this problem. They range from a list of (attribute, regexp) tuples that you apply in a per-object basis to more complex things.

    One option is to find some kind of declarative “language” with which you can specify simple queries such as the one you mention. This can be something that would be stored in a JSON or YAML structure, it all depends on how complex/extensible you want it to be.

    If you want it to be really extensible, you may event want to have a DSL (domain-specific language):

    http://www.slideshare.net/Siddhi/creating-domain-specific-languages-in-python

    Here is a past StackOverflow post that may be helpful.

    Writing a Domain Specific Language for selecting rows from a table

    The simplest solution I can see (to parse, generate and store) is a LISP-style prefix list of tuples, such as:

    [('and', ('body', '.*to be or not.*'), ('author', (not, '.*shakespeare.*'))),
     ...]
    

    If all you need is basic boolean operators and RegExs, that should be enough.

    [Edit] Added example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have a reasonable size flat file database of text documents mostly saved in
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.