-2

I currently have a large string big_string that contains elements like:

..."string1":"74f07sdfafeijsfeijfsl","string2":"XRewejffeew","zero_data":{},"string3":"c2d8f4380025",...

I would like to extract the string after "string2", so that I can have a variable:

substring = 'XRewejffeew'

Is there a way to do this with re.findall()?

user321627
  • 2,350
  • 4
  • 20
  • 43
  • Parse the JSON instead, if at all possible – CertainPerformance Aug 27 '18 at 04:59
  • 1
    Yes there is, have you even attempted to do it before asking? – Julien Aug 27 '18 at 04:59
  • There are a lot of data requirements and points of interests that I would want to know before making any suggestions. Are commas allowed in the `value`? is everything a basic `key`:`value` pair? Are quotes allowed in either `key`s or `value`s? – T.Woody Aug 27 '18 at 05:02
  • Possible duplicate of [Parsing values from a JSON file?](https://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file) – tripleee Aug 27 '18 at 05:06

1 Answers1

1
findall('(?<="string2":")\w+', big_string) # Result: 'XRewejffeew'

For explainations look here:

Getting the text that follows after the regex match

nicksheen
  • 550
  • 6
  • 23