标题如“Title = The = operator”.以下是解决问题的两种选择:
^([^=]+)=(.+)$ ^(.+?)=(.+)$
解决方法
根据您的内容,第一个可以显着更快地运行. Here’s why:
An Alternative to Laziness In this case,there is a better option than making the plus lazy. We can use a greedy plus and a negated character class: <[^=]+>. The reason why this is better is because of the backtracking. When using the lazy plus,the engine has to backtrack for each character in the HTML tag that it is trying to match. When using the negated character class,no backtracking occurs at all when the string contains valid HTML code. Backtracking slows down the regex engine. You will not notice the difference when doing a single search in a text editor. But you will save plenty of cpu cycles when using such a regex repeatedly in a tight loop in a script that you are writing…