I think it does what you're expecting if you change the pattern so the 
whitespace match isn't greedy: ^\s*?$

\s matches returns and newlines so your pattern ^\s*$ should match any block of 
lines which contain only whitespace. With the non-greedy modifier it instead 
stops at the first end-of-line it finds so cycles through each line which 
contains only whitespace in turns.

I am seeing some strange behavior, which you mention, where if the cursor is at 
the start of the file it only matches lines 2 through 3, but upon wrapping 
around it matches lines 2 through 4 as I'd expect.

[fletcher]


> On Jan 12, 2017, at 11:22 AM, Sam Hathaway <[email protected]> wrote:
> 
> Patrick,
> 
> Say I have this file:
> ----8<-cut-here----
> one
> 
> 
> 
> two
> ----8<-cut-here----
> 
> (Line 2 and 4 are empty, line 3 consists of four spaces.)
> 
> And this pattern: ^\s*$
> 
> Shouldn’t it match these three ranges?
> - zero chars on line 2
> - four spaces on line three
> - zero chars on line 3
> 
> Instead, it seems to match only one range:
> - 6 chars: the linefeed at the end of line 2, the four spaces on line three, 
> and the linefeed at the end of line 3.
> 
> I’m still not seeing why ^\s*$ would match chars 5 through 10 (the first 
> empty line AND the line with 4 spaces) in one fell swoop, but would not match 
> char 11 (the 2nd empty line).
> 
> Shouldn’t it match these three ranges?
> - zero chars after char 4
> - four chars (“    ”) starting with char 6 and ending with char 9
> - zero chars after char 10
> 
> Confused!
> -sam
> 
> On 12 Jan 2017, at 10:46 AM EST, Patrick Woolsey wrote:
> 
>> On 1/11/17 at 8:59 PM, [email protected] (Mike Pullen) wrote:
>> 
>>> ^\s*$ does not work for me in BBEdit.  BBEdit does not find the empty lines 
>>> that proceeds the line containing "four" or the line containing "six" in my 
>>> test file.
>> 
>> It isn't expected to, since $ explicitly matches the position _preceding_ 
>> the nearest line end:
>> 
>> [Chapter 8: Searching with Grep / page 166]
>> 
>>    It is important to note that ^ and $ do not actually match return
>>    characters. They match zero-width positions after and before returns,
>>    respectively. So, if you are looking for “foo” at the end of a line,
>>    the pattern "foo$" will match the three characters "f", "o", and "o".
>>    If you search for "foo\r", you will match the same text, but the
>>    match will contain four characters: "f", "o", "o", and [the
>>    linebreak which follows].
>> 
>> 
>> 
>> Regards,
>> 
>> Patrick Woolsey
>> ==
>> Bare Bones Software, Inc.             <http://www.barebones.com/>
>> 
>> -- 
>> This is the BBEdit Talk public discussion group. If you have a feature 
>> request or would like to report a problem, please email
>> "[email protected]" rather than posting to the group.
>> Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
>> --- You received this message because you are subscribed to the Google 
>> Groups "BBEdit Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/bbedit.
> 
> -- 
> This is the BBEdit Talk public discussion group. If you have a feature 
> request or would like to report a problem, please email
> "[email protected]" rather than posting to the group.
> Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
> --- You received this message because you are subscribed to the Google Groups 
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/bbedit.

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.

Reply via email to