Mom no longer have to worry about my regularity!
I used to write a Python module that automatically generates regular expressions, but I didn’t have a good technical solution. Suddenly this morning, a flash of light flashed, and wrote a CreateRe module in one go. To be honest, the ability to generate regularity is general. This module can generate simple regular expressions. It is suitable for beginners. It can be used by young people who don’t understand regular expressions and don’t want to learn regular rules. It is simple and convenient to generate one-click. If you have troublesome young people who want to learn regular grammar, please go to: [Python regular expression] (https://thief.one/2017/10/30/1/)
Python generates a regular expression module that is used to generate regular expressions in reverse. You can generate a regular expression by simply passing in the string to be matched and the list of results you expect to match.
Of course, the current module is not mature enough, the specific performance is: the first generation ability is limited (complex may not be generated), and the second is that the generated regular expression is not easy enough (we know the same matching effect, there can be many kinds of regular expressions to go Realization, experts can often write the shortest and optimal optimization rules, and this module is still in the introductory stage), only suitable for regular beginners.
Import the CreateRe module, use the instance, you can refer to the test.py file in the project.
- STRING string to be matched, must be in unicode format
- S predicts a list of regular match results, must be List, and if there is a Chinese option in the list, it needs to be unicode format
- tag greedy matching switch, the specific difference will be introduced below
When changing the value of the tag, tag=True, the result is:
Description: tag=True means to enable greedy matching, that is, the generated regular will match the result as much as possible. The default is False.
The value of S can also be specified multiple:
If you change the tag to False, the result is:
Returning check_res=False indicates that the generated regular expression does not match the desired result; you can change the tag to True to try.
- Regular expression generated by the RES module
- check_result uses regular expressions to generate results that are compared to expectations. If False is returned, it means failure, and returning a result list means success.