找到写得很糟的正则表达式

时间:2016-12-05 21:05:46

标签: java python

为了帮助我学习正则表达式,我试图改进那些写得不好的现有正则表达式。

阅读https://www.loggly.com/blog/five-invaluable-techniques-to-improve-regex-performance

   var formData = ['key' => value], than i get unexpected string

要自动执行查找性能较差的正则表达式的过程,我正在考虑编写一个脚本,该脚本将使用上述规则检查每个正则表达式。例如,搜索score=0 print("Welcome the the general knowledge quiz") your_name = input("What is your name?: ") input("Press Enter to Start the Quiz!") print("1) Who presents Pointless?") answer = input() if answer == ["Alexander Armstong", "alexander armstrong", "ALEXANDER ARMSTRONG"]: print("Well done", your_name) score = score+1 else: print("Sorry, the answer was Alexander Armstrong") print("Your score is", score) print("2) Who presents I'm a celeb, get me out of here?") answer = input() if answer == ["Ant and Dec", "ant and dec", "ANT AND DEC", "Ant And Dec"]: print("Well done", your_name) score = score+1 else: print("Sorry, the answer was Ant and Dec") print("Your score is", score) print("3) What is the capital of England?") answer = input() if answer == ["London", "london", "LONDON"]: print("Well done", your_name) score = score+1 else: print("Sorry, the answer was London") print("Your score is", score) print("4) Who lives on the White house right now?") answer = input() if answer == ["Obama", "obama", "Barack Obama", "barack obama"]: print("Well done", your_name) score = score+1 else: print("Sorry, the answer was Barack Obama") print("Your score is", score) 以检查每个正则表达式中的字符类。如果正则表达式不包含字符类,那么它可能是性能优化的候选者。

我是否可以使用其他基于规则的方法来检查正则表达式的性能。

或许也许有一个Java / Python库目前正在实现这个功能?

0 个答案:

没有答案