Wirte a regular expression pattern to match all words ending in s.

This is what I got but seems like im thinking to hard on it, plus of course its not working lol Please help! :)

import re
str = "Subs are everwhere"
print (str)
matchObj = re.match(".*?s ",str,re.L|re.I)
if matchObj:
   print ("matchObj.group() : ", matchObj.group())
   print ("none found")
6 Years
Discussion Span
Last Post by kate2mba

Something like this,look into findall off re module.
Dont use str as variable,it`s a builtin key word.

>>> str
<type 'str'>
>>> help(str)
Help on class str in module __builtin__:
>>> import re
>>> help(re.findall)
Help on function findall in module re:

findall(pattern, string, flags=0)
    Return a list of all non-overlapping matches in the string.
    If one or more groups are present in the pattern, return a
    list of groups; this will be a list of tuples if the pattern
    has more than one group.
    Empty matches are included in the result.
import re

text = '''\
Subs cars are test driving in space,and many pigs are flying.

test_match = re.findall(r'\w+[s]\b', text)
print test_match
#->['Subs', 'cars', 'pigs']
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.