Q:

Regex comparison

I'm (finally) starting to learn regex, and I'm wondering if there's any notable difference between these two pattern strings. I'm trying to match lines such as "Title=Blah", and match "Title" and "Blah" in two groups.
The problem comes with titles like "Title=The = operator". Here are the two choices to solve the problem:
^([^=]+)=(.+)$
^(.+?)=(.+)$

Is there any difference between the two, either performance-wise or functionality-wise?

A:

The first one requires that there be at least one non-= character before an = in order to match, where the second doesn't; it'll match on a leading ==.
As to performance, I don't anticipate a meaningful difference, but if you truly care, the only thing to do is profile it.  Which I would do by writing a pair of scripts, each running one of the methods a few hundred thousand times, and timing them using the Unix time command.

A:

The first one requires that there be at least one non-= character before an = in order to match, whereas the second doesn't; it'll match on a leading ==.
Depending on your content, the first one could run significantly faster. 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...

