-3

I have a file in the following format:

someinformation="someNumbers"-result

My code is:

re.findall('someinformation="(.*?)"-result', str(data))

Given the example:

test1="3"-result

I want to get 3, but my code doesn't find anything.

re.findall('test1=(.*?)-result', str(data))

works, but returns "3" and not 3. What I find strange is that the following:

  re.findall('test1="3"-result', str(data))

doesn't find anything either.

mat
  • 77
  • 1
  • 1
  • 6

1 Answers1

0

You have a syntax error in following code :

re.findall('test1="3"-result'), str(data))

Just remove the extra parenthesis and see the result,also note that if you defined your string like following you won't need to use str function at all :

>>> data='test1="3"-result'
>>> re.findall('test1="3"-result', data)
['test1="3"-result']
Mazdak
  • 105,000
  • 18
  • 159
  • 188
  • sry, my mistake, the code om my side is correct, i posted it wrong, however my problem remains – mat Oct 06 '15 at 15:25
  • @mat Did you have defined your string like mine? why use used `str`? – Mazdak Oct 06 '15 at 15:28
  • this might be the problem, data is a list of strings, and by casting it to a string i thought i could combine the strings, but this might have been a mistake. Is there a way to solve this issue? – mat Oct 06 '15 at 15:47
  • @mat Indeed, converting the a list to string with `str` will include the brackets too, can you add the data to your question? – Mazdak Oct 06 '15 at 15:50
  • The data is basicly as indicated in my first "code" line, severeal lines of data, where i want to read the number from each line. The data variable is the result of a nother regex call which extracts all the lines containing the results. – mat Oct 06 '15 at 16:03