1

Possible Duplicate:
Difference between .? and . for regex

I was reading this question, and noticed that many of the regular expressions in the answers used .*? to match intermediate text, rather than just .*.

To my mind, using .* will match any character zero or more times. Adding ? would be superfluous, as it would just modify "zero or more" to "zero or more once, or nothing" (in other words, "zero or more, or zero").

Does .*? represent a special regex sequence, or is it just an odd way to write .* with more characters?

Community
  • 1
  • 1
Emperor XLII
  • 13,014
  • 11
  • 65
  • 75
  • 1
    `?` following repetition specifier is the reluctant/lazy/non-greedy quantifier. See my lengthy answer with examples http://stackoverflow.com/questions/3075130/difference-between-and-for-regex/3075532#3075532 – polygenelubricants Aug 28 '10 at 20:49
  • @polygenelubricants Thanks! Unfortunately, searching for ".*?" hadn't turned up anything, despite being in the title for that original question. Yours is just the answer I was looking for :) – Emperor XLII Aug 29 '10 at 23:28

0 Answers0