-1

re.search looks for the first instance of something. In the following code, "\t" appears twice. Is there a way to make it skip forward to the second instance?

code = ['69.22\t82.62\t134.549\n']
list = []
text = code
m = re.search('\t(.+?)\n', text)
if m:
    found = m.group(1)
    list.append(found)

result:

list = ['82.62\t134.549']

expected:

list = ['134.549']
Barmar
  • 741,623
  • 53
  • 500
  • 612
Jason Reed
  • 63
  • 6

2 Answers2

1

This modified version of your expression does return the desired output:

import re

code = '69.22\t82.62\t134.549\n'
print(re.findall(r'.*\t(.+?)\n', code))

Output

['134.549']

I'm though guessing that maybe you'd like to design an expression, somewhat similar to:

(?<=[\t])(.+?)(?=[\n])

DEMO

Emma
  • 27,428
  • 11
  • 44
  • 69
1

There is only one solution for greater than the "second" tab.
You can do it like this :

^(?:[^\t]*\t){2}(.*?)\n

Explained

 ^                     # BOS
 (?:                   # Cluster
      [^\t]*                # Many not tab characters
      \t                    # A tab
 ){2}                  # End cluster, do 2 times
 ( .*? )               # (1), anything up to
 \n                    # first newline

Python code

>>> import re
>>> text = '69.22\t82.62\t134.549\n'
>>> m = re.search('^(?:[^\t]*\t){2}(.*?)\n', text)
>>> if m:
>>>     print( m.group(1) )
...
134.549
>>>