On 8/8/06, Ronald J Kimball said:
> For the record, this is not a bug. Here's what happens:
>
> Text
> example
>
> Find
> (.*)
>
> The regex engine starts out trying to match at the beginning of the string,
> just before the first e. .* matches the e, then the x, and so on until it
> has matched 'example'. . can't match newline, and as that's the end of
> the regex, a successful match has been found.
[snip]
I'm not trying to make a big issue out of this — obviously, it's up to
BareBones to say if this is actually a bug or not — but just because you can
explain what's happening doesn't mean it's not a bug.
I think it's a bug.
.* is supposed to match everything except newlines (unless you use the flag
that says it matches newlines also).
- Regular expressions are greedy by default, so the first thing that can
be matched after a greedy, no-line-feed .* is the next line.
- If you've matched everything except the carriage return, it doesn't
make any sense to then match the "nothing" between the last character
in the line and the carriage return.
- The "everything" you matched already was supposed to include that
"nothing" after the last character.
Here's a perl example that shows how it should work.
Create a test file called test.txt. Put a few lines in it, just one word per
line (to keep it short and simple). Save it at ~/Desktop/test.txt
Open terminal, and run these two lines:
cd ~/Desktop
perl -pi -e 's/(.*)/($1)/' test.txt
The second line tells perl to run a search for every .*, and replacing each
with the same text but wrapped in parentheses.
Open the file in BBEdit again, and you'll see that each line is wrapped in
parens, and that's the only change.
So if a line contains just "foo", it will be replaced with "(foo)".
Now change the file back to the way it was (without the parens), and run the
same find-and-replace in BBEdit:
- turn on grep
- search for (.*)
- replace with (\1)
and click "replace all". You get an extra set of empty parens at the end of
every line.
This is a bug. (Never would have believed it if I hadn't seen it for
myself! ;-)
(Not that this is a big deal, since there seems to be a pretty easy
workaround.)
Seth
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>