Picking up field value using Python regex
Question: This is an example of two lines in a file that I am trying to pick up
information from.

    
    
    ...
    { "SubtitleSettings_REPOSITORY", FieldType_STRING, (int32_t)REPOSITORY},
    { "PREFERRED_SUBTITLE_LANGUAGE", FieldType_STRING,SUBTITLE_LANGUAGE},
    ...
    

What I want to do is to find out the 3rd field of this weird data structure
for the given string to match to 1st field, i.e.

    
    
    SubtitleSettings_REPOSITORY => REPOSITORY
    PREFERRED_SUBTITLE_LANGUAGE => SUBTITLE_LANGUAGE
    

The regx in my Python code can only handles the second line, but not cope with
the first line. How I can improve it?

    
    
    import re
    ...
    #field is given a value in previous code, can be "SubtitleSettings_REPOSITORY", or "PREFERRED_SUBTITLE_LANGUAGE"
    match = re.search(field+'"[, \t]+(\w+)[, \t]+(\w+)', src_file.read(), re.M|re.I)
    return_value = match.group(2)
    


Answer: 
    import re
    with open("input.txt") as f:
      pattern = "\{ \"(.+)\",.+,(.+)\}"
      for line in f:
        first, third = re.findall(pattern, line.strip())[0]
        print first.strip(), "=>", third.strip()
    

prints

    
    
    SubtitleSettings_REPOSITORY => (int32_t)REPOSITORY
    PREFERRED_SUBTITLE_LANGUAGE => SUBTITLE_LANGUAGE
    

where `input.txt` contains

    
    
    { "SubtitleSettings_REPOSITORY", FieldType_STRING, (int32_t)REPOSITORY},
    { "PREFERRED_SUBTITLE_LANGUAGE", FieldType_STRING,SUBTITLE_LANGUAGE}
    

**Breakdown:**

  * `\{ \"(.+)\"` matches strings with the structure **{ + space + " + text + "** and extracts **text**
  * `,.+,(.+)\}` matches strings with the structure **, + text1 + , + text2 + }** and extracts **text2**

