Using python to find specific pattern contained in a paragraph
Question: I'm trying to use python to go through a file, find a specific piece of
information and then print it to the terminal. The information I'm looking for
is contained in a block that looks something like this:

    
    
    \\Version=EM64L-G09RevD.01\State=1-A1\HF=-1159.6991675\RMSD=4.915e-11\RMSF=1.175e-07\ZeroPoint=0.0353317\
    

I would like to be able to get the information `HF=-1159.6991675`. More
generally, I would like the script to copy and print
`\HF=WhateverTheNumberIs\`

I've managed to make scripts that are able to copy an entire line and print it
out to the terminal, but I am unsure how to accomplish this particular task.


Answer: My suggestions is to use regular expressions
([regex](https://docs.python.org/2/howto/regex.html)) in order to catch the
required pattern:

    
    
    import re #for using regular expressions
    s = open(<filename here>).read() #read the content of the file and hold it as a string to be scanned
    p = re.compile("\HF=[^\]+", re.flags)  #p would be the pattern as you described, starting with \HF= till the next \)
    print p.findall(s) #finds all occurrences and prints them 
    

