Loading regular expression patterns from external source?
Question: I have a series of regular expression patterns defined for automated
processing of text. Due to the design of the program, it's better to have
these patterns separate in a text file, namely a JSON file. The pattern in
Python is of `r''` type, but all I can provide is a string. I'd like to retain
functionalities such as grouping. I'd like to have features such as entities
(`[A-z]`), so I'm not talking about escaping everything.

I'm using Python 3.4. How do I properly load these patterns into the `re`
module? And what kind of escaping problem should I watch out for?


Answer: I am not sure what you want but have a look at this.:

If you have a file called input.txt containing `\d+`

Then you can use it this way:

    
    
    import re
    f=open("input.txt","r")
    x="asasd3243sdfdsf23234sdsdf"
    print re.findall(r""+f.readline(),x)
    

Output:`['3243', '23234']`

When you use `r` mode you need not escape anything.

