0

The data files which I have look like:

Title
10000XX   1.09876543e+02

There are many lines in this form with the column 1 values ranging from 1000000-2000099 and with column 2 values ranging from -9000 to 9000 including some values with negative exponents. I am very new to regex so any help would be useful. The rest of my program is written in python so I am using:

re.search()

Some help with this syntax would be great. Thanks

user1431534
  • 13
  • 1
  • 1
  • 5
  • 1
    Use the `split()` function. http://www.tutorialspoint.com/python/string_split.htm – Robert Harvey Jun 11 '12 at 17:57
  • 1
    Regex is often used to extract patterns from data. What exactly do you want to extract? – David B Jun 11 '12 at 18:00
  • It doesn't sound like you need regular expressions at all for this. In general it's better to use simpler and more direct methods (see deadly's answer) unless regular expressions really are needed. – weronika Jun 11 '12 at 23:07

1 Answers1

3

As Robert says, you can just use the split() function.

Assuming the separator is spaces like you have in the question, you can run the code below to give a list of values, then do with that as you will:

>>> line = "10000XX   1.09876543e+02"
>>> line.split()
['10000XX', '1.09876543e+02']

You can convert the second item to a floating point number with float(). e.g. float('1.09876543e+02')

Just iterate over your lines and ignore any that don't start with a number.

Regular expressions are a bit more fiddly.

deadly
  • 1,194
  • 14
  • 24