py4sci

Previous topic

common

Next topic

find

This Page

regex

Note

Functions for string parsing.

Module author: Adam Gagorik <adam.gagorik@gmail.com>

regex.number(string, index=0, pytype=<type 'float'>)[source]

Get numbers in a string at index and convert them.

Parameters:
  • string (str) – string
  • index (int) – which regex group to match
  • pytype (type) – python type to convert to
>>> print lm.regex.number('asdfasdfa1.231e10')
12310000000.0
regex.numbers(string, pytype=<type 'float'>)[source]

Find all numbers in a string and convert them.

Parameters:
  • string (str) – string
  • pytype (type) – python type to convert to
>>> print lm.regex.numbers('asdfasdfa1.231e10asdf1209asd asd0912 sdaf9 81')
[12310000000.0, 1209.0, 912.0, 9.0, 81.0]
regex.strip_comments(string)[source]

Return string will all comments stripped.

Parameters:string (str) – string
>>> print lm.regex.strip_comments('hello # goodbye')
hello
regex.fix_boolean(string)[source]

Return string with true/false in correct python format.

Parameters:string (str) – string
>>> print lm.regex.fix_boolean('true false True False true false')
True False True False True False
regex.run(string)[source]

Extract run from string.

Parameters:string (str) – str
>>> print lm.regex.run('run.2')
2
regex.part(string)[source]

Extract part from string.

Parameters:string (str) – str
>>> print lm.regex.run('part.3')
3