# get_regex¶

get_regex(filename, patterns, encoding='utf-8')

Get values from a file using regex.

Parameters: filename : str The name of the file to parse patterns : list of str Regex patterns that will permit to get the values see https://docs.python.org/2/library/re.html for available patterns The value to be searched must be surrounded by parenthesis. encoding : str File encoding see http://docs.python.org/2/library/codecs.html#codec-base-classes results : list of float Each value corresponds to each pattern. If nothing has been found, the corresponding value is set to None. AssertionError parameters badly set EOFError no value found

Examples

>>> import openturns.coupling_tools as otct
>>> # write an output file
>>> with open('results.out', 'w') as f:
...     count = f.write('@E=-9.5E3')
>>> # parse file with regex
>>> otct.get_regex('results.out', patterns=['@E=(\R)'])
[-9500.0]