regular expression match issue in Python
Question: For input string, want to match text which starts with `{(P)` and ends with
`(P)}`, and I just want to match the parts in the middle. Wondering if we can
write one regular expression to resolve this issue?

For example, in the following example, for the input string, I want to
retrieve _hello world_ part. Using Python 2.7.

    
    
    python {(P)hello world(P)} java
    


Answer: You can try `{\(P\)(.*)\(P\)}`, and use parenthesis in the pattern to capture
everything between `{(P)` and `(P)}`:

    
    
    import re
    re.findall(r'{\(P\)(.*)\(P\)}', "python {(P)hello world(P)} java")
    
    # ['hello world']
    

`.*` also matches unicode characters, for example:

    
    
    import re
    str1 = "python {(P)£1,073,142.68(P)} java"
    str2 = re.findall(r'{\(P\)(.*)\(P\)}', str1)[0]
    
    str2
    # '\xc2\xa31,073,142.68'
    
    print str2
    # £1,073,142.68
    

