-2

I am trying to find the regular expression for getting the Error value from the following string:

{'Sample': '#it{House}', 'Yield': 0.0012267869301467726, 'Error': 0}

I tried "'Error': (\d+.\d+)" but I have the case that the Error can be either an integer (like 0) or a double value like 0.992. I checked many cases but still cannot find the regular expression.

Chris S.
  • 131
  • 1
  • 7

1 Answers1

0

If that data is indeed formatted with yaml, you can read it with the yaml module (which is not part of the default distribution of python):

$ python -c 'import yaml,sys; print(yaml.load(sys.stdin.read())["Yield"])' <<<"{'Sample': '#it{House}', 'Yield': 0.0012267869301467726, 'Error': 0}"
0.00122678693015
erik258
  • 14,701
  • 2
  • 25
  • 31