The reason the first
.* doesn't match the whole string is because the regex is like a persistent ex, it doesn't want to lose. Regexes try hard to match. The regex
/.*](.*)/ matches as much of the string as possible, and then tries to match a bracket. When it realizes it can't, it backs up to the last bracket it passed, and then tries matching the rest of the regex. This process is called "backtracking" and is an integral part of any regular expression engine.
I could tell you that it backtracks one character at a time until it finds a bracket, but that's not true. It's optimized in a case like this to jump backwards to the bracket all at once.
_____________________________________________________
Jeff
[japhy]Pinyan:
Perl,
regex,
and
perl
hacker, who'd like a
job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;