[ create a new paste ] login | about

Link: http://codepad.org/OIazr9lA    [ raw code | output | fork ]

bytecolor - Python, pasted on Oct 24:
import re

data = """
1.0000E-08

1.0000E-08 1.58024E-06 0.0048 1.0000E-08 1.58024E-06 0.0048
foo bar baaz
1.0000E-06 8.85470E-06 0.0026
1.0000E-05 6.08120E-06 0.0032
1.0000E-03 1.61817E-05 0.0022
1.0000E+00 8.34460E-05 0.0014
2.0000E+00 2.31616E-05 0.0017
5.0000E+00 2.42717E-05 0.0017
total 1.93417E-04 0.0012
"""

ntuple = re.compile(r"""
# match beginning of line (re.M in the docs)
^
# chew up anything before the first real (non-greedy -> ?)
.*?
# named match (turn the match into an atom while allowing irrelevant (groups))
(?P<ntuple>
  # match one real
  [-+]?(\d*\.\d+|\d+\.\d*)([eE][-+]?\d+)?
  # followed by zero or more space separated reals
  ([ \t]+[-+]?(\d*\.\d+|\d+\.\d*)([eE][-+]?\d+)?)*)
# match end of line (re.M in the docs)
$
""", re.X | re.M) # re.X to allow comments and arbitrary whitespace
print [tuple(mo.group('ntuple').split())
       for mo in re.finditer(ntuple, data)]


Output:
1
[('1.0000E-08',), ('1.0000E-08', '1.58024E-06', '0.0048', '1.0000E-08', '1.58024E-06', '0.0048'), ('1.0000E-06', '8.85470E-06', '0.0026'), ('1.0000E-05', '6.08120E-06', '0.0032'), ('1.0000E-03', '1.61817E-05', '0.0022'), ('1.0000E+00', '8.34460E-05', '0.0014'), ('2.0000E+00', '2.31616E-05', '0.0017'), ('5.0000E+00', '2.42717E-05', '0.0017'), ('1.93417E-04', '0.0012')]


Create a new paste based on this one


Comments: