Q:

Filter based on expression match

I've been combing over regex related websites and tutorials to figure out how to accomplish this but unfortunately still can't get a clear grasp on regular expressions.  I have forum posts that have been tokenized and am trying to filter them based on posts that may have age related info.  
For example, I used this snippet to try to filter:
re.search(r'.*(daughter|ds|son|dd|) (is|was|is turning|turned) ([0-9]{2})*', post)

This works on text such as the string
'my son was 7 when this incident occurred'

but also on the string
'is'

To filter,
r = re.compile('.*(daughter|ds|son|dd|)(is|was|is turning|turned)([0-9]{2}).*')
filter(r.match, ['my daughter is 7', 'is'])

but this returns an empty list when there should be a match with the first string.
What is wrong with the code snippet and what are some pointers to help with regular expression matches for my filtering?

A:

Couple of things to correct:
1 - In your regular expression:
.*(daughter|ds|son|dd|)(is|was|is turning|turned)([0-9]{2}).*

You are not taking into consideration the space characters between the words, so it will be:
.*(daughter|ds|son|dd|).*(is|was|is turning|turned).*([0-9]{2}).*
                       ^^                          ^^

2 - In the age group, you asking to only look for ages made of two numbers, so 7 will not match, thus you have to do it this way:
.*(daughter|ds|son|dd|).*(is|was|is turning|turned).*([0-9]{1,2}).*
                                                            ^

DEMO:
>>> r = re.compile('.*(daughter|ds|son|dd|).*(is|was|is turning|turned).*([0-9]{1,2}).*')
>>> l =filter(r.match, ['my daughter is 7', 'is'])
>>> 
>>> 
>>> l
['my daughter is 7']
>>> 

