in reply to Do nothing? or Do something important in a very obscure way?
/x?/ means match x zero or one times, but prefer 1...
i.e. Match it if you can
i.e. Match it if you can
/x??/ means match x zero or one times, but prefer 0...
i.e. Match it if you have to
For instance:
The notation is a little confusing because the two question marks in a row mean different things. /x?/ is really just syntatic sugar for /x{0,1}/. The second question mark turns on min matching. When you look at it this way, the difference between /x{0,1}/ and /x{0,1}?/ should be more clear.% perl -le '"wxy" =~ /(wx?)/; print $1' 1:wx % perl -le '"wxy" =~ /(wx??)/; print $1' 1:w % perl -le '"wxy" =~ /(wx?y)/; print $1' 1:wxy % perl -le '"wxy" =~ /(wx??y)/; print $1' 1:wxy
-Blake
In Section
Meditations