python regex, optionally match a word
Question: I have the following regex:

    
    
    PackageQuantity:\b|Servings?PerContainer:\b|Servings?PerPackage:\b(\d+)
    

that supposed to match the following text:

    
    
    ServingsPerContainer:about11
    

Blank white spaces are escaped for comfortability

the idea is, that the words `Package Quantity`, `Servings per container` or
`servings per package` can be followed by any word (exactly one word), such as
`approx.`, or `about`.

Seems simple enough, but I couldn't find a solution, since the regex above
matches an empty string instead of the figure

pythonregex.com output:

    
    
    >>> regex = re.compile("PackageQuantity:\b|Servings?PerContainer:\b|Servings?PerPackage:\b(\d+)",re.IGNORECASE)
    >>> r = regex.search(string)
    >>> r
    <_sre.SRE_Match object at 0x672858ed0eef4da0>
    >>> regex.match(string)
    <_sre.SRE_Match object at 0x672858ed0ee8c6a8>
    
    # List the groups found
    >>> r.groups()
    (None,)
    
    # List the named dictionary objects found
    >>> r.groupdict()
    {}
    
    # Run findall
    >>> regex.findall(string)
    [u'']
    
    # Run timeit test
    >>> setup = ur"import re; regex =re.compile("PackageQuantity:\b|Servings?PerContainer:\b|S ...
    >>> t = timeit.Timer('regex.search(string)',setup)
    >>> t.timeit(10000)
    0.0259890556335
    


Answer: You are missing the optional word after the `:`

Either
[(PackageQuantity:|(Servings)?PerContainer:|(Servings)?PerPackage:)[a-zA-Z.]*(\d+)](http://regex101.com/r/vT0uY6/1)
or
[(PackageQuantity:|(Servings)?PerContainer:|(Servings)?PerPackage:)(about|approx.)?(\d+)](http://regex101.com/r/hT0jP3/1)
if your list of words is not too long should do the trick

