Q:

Hows does the Regular Expression: /.+?/ work?

How would the '.+?' regular expression work? Is the .+ part matching anything written, and the ? part saying it can either be there or not? So, for example, this regular expression would match:
'cat'
'' (ie, nothing written, just the empty string)

A:

The "+?" is not a "+" quantifier followed by a "?" quantifier. Instead the "?" modifies the "+" to perform a "lazy" or "non greedy" match, meaning that the least number of characters that match is already sufficient.
So a "a+?" regex would match just a single "a" in "caaat".

A:

Besides what Hans Kesting already said, a lazy multiplier will do the exact oposite of the normal greedy multipliers: The possible match is kept as small as possible and the rest of the regular expression is tested.
So if you’re having the string aaba and test the regular expression a.*b on it, the internal processing steps would be as follows:

a in a.*b matches aaba
.* in a.*b matches aaba, and since .* is greedy

.* then matches aaba
.* then matches aaba

b in a.*b fails as there is no letter left

backtracking goes one step back and .* will now only match bb in aaba

b in a.*b still fails on aaba

backtracking goes one step back and .* now matches only b in aaba

b in a.*b now matches b in aaba and we’re done.

So the full match is aaba.
If we do the same with a lazy multiplier (a.*?b), the processing will do the oposite, try to match the least possible characters as possible:

a in a.*?b matches aaba
.* in a.*?b matches nothing (* = zero or more repetitions), and since .* is declared as lazy (.*?), the rest of the regular expression is tested
b in a.*?b fails on aaba

backtracking will try to increase the match of .*

.* matches now aaba
b in a.*?b matches aaba and we’re done.

So the full match if aaba.

A:

+? (lazy plus) 

Repeats the previous item once or
  more. Lazy, so the engine first
  matches the previous item only once,
  before trying permutations with ever
  increasing matches of the preceding
  item.

/".+?"/ matches "def" (and "ghi") in abc "def" "ghi" jkl, while /".+"/ matches "def" "ghi".
You can find more info here

