Greedy GREP

2011-08-12 Thread Warren Michelsen
I must be misunderstanding how {1}? works.

I have documents that contain three instances of lines starting with "time : "

With these documents, I need to do two things:

1) eliminate from the first instance  of ^(time : ) up to but not including the 
second instance; and

2) eliminate the third instance of ^(time : ) and everything after it up to but 
not including the line starting with "startTime : "

I would expect (^time : (?s).*) to match the entire document and it does. 

So where do I place the {1}? to limit the find to the second, not third 
instance of ^time : ?

Using "(^(time : ){1}?(?s).*)^time" selects up to the third ^time.



-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at

If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 


Re: Greedy GREP

2011-08-13 Thread John Delacour

At 23:50 -0500 12/08/2011, Christopher Stone wrote:

Ronald will no doubt come up with something brilliant, and JD will 
likely come up with a nice Perl filter.


:)


You bet!

#! /usr/bin/perl
while (<>) {
  $found++ if /^time/i;
  print if $found == 2;
}



That's presuming you have something like

time : 01:15
other
other
time : 2:15
other
other
time : 03:15
other
other

and you want

time : 02:15
other
other

--
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.

To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at

If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.

Follow @bbedit on Twitter: 


Re: Greedy GREP

2011-08-13 Thread John Delacour
Let's try that again with HTML.  Google always gets plain text wrong 
in the display in the web archive.  Google things are designed by 
neanderthals with no idea what an RFC is.  I wish Barebones would 
transfer the list to ListServ or some other decent list server.


#! /usr/bin/perl
while (<>) {
  $found++ if /^time/i;
  print if $found == 2;
}

JD

--
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.

To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at

If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.

Follow @bbedit on Twitter: 


Re: Greedy GREP

2011-08-13 Thread Ronald J Kimball
On Fri, Aug 12, 2011 at 09:11:08PM -0700, Warren Michelsen wrote:
> I must be misunderstanding how {1}? works.

Normally, quantifiers (? * + {n,m}) match as many times as possible.
Adding a ? after a quantifier makes it match as few times as possible.
(To be more precise, normally the longest leftmost match is found; adding ?
after a quantifier means the shortest leftmost match is found.)

So, {n}? means match exactly n times, but as few as possible.  But the only
possibility is exactly n times, so adding the ? doesn't have any effect.

Further, {1} means match exactly 1 time.  But without a quantifier it
matches 1 time anyway, so {1} also has no effect.


> I would expect (^time : (?s).*) to match the entire document and it does. 
> 
> So where do I place the {1}? to limit the find to the second, not third 
> instance of ^time : ?
> 
> Using "(^(time : ){1}?(?s).*)^time" selects up to the third ^time.

I believe this is what you're looking for:

(^time : (?s).*?)^time

You want to match any character, as few times as possible to get to ^time.

You were on the right track; you were just adding the question mark in the
wrong place.


Ronald

-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at

If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 


OFFLIST :: Re: Greedy GREP

2011-08-12 Thread Christopher Stone
On Aug 12, 2011, at 23:11, Warren Michelsen wrote:
> I must be misunderstanding how {1}? works.

__

Hey Warren,

Document Body:

time time time time time time time time time time time time 

Find String:

(time ){2}

Your explanation isn't bad, but it would be much better to provide a real data 
sample.  Without seeing same there are a few too many variables.

Here though is an approximation:

Find String:

(?s)(time : .+?)(?=time : )((time : .+?)(?=time : ))(time : .+?)(?=startTime :)

Replace String:

\2

Ronald will no doubt come up with something brilliant, and JD will likely come 
up with a nice Perl filter.

:)

--
Best Regards,
Chris

-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at

If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 


Multi-line, Non-Greedy GREP Find

2009-08-19 Thread Warren Michelsen

How do I get this pattern to stop after finding the first "" tag? I want 
to replace  tags that span multiple lines.

([\s\S]*)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Multi-line, Non-Greedy GREP Find

2009-08-19 Thread Ronald J Kimball

On Wed, Aug 19, 2009 at 10:24:29AM -0700, Warren Michelsen wrote:
> 
> How do I get this pattern to stop after finding the first "" tag? I
> want to replace  tags that span multiple lines.
> 
> ([\s\S]*)

The simplest way is by using a non-greedy quantifier:

([\s\S]*?)

Ronald

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Multi-line, Non-Greedy GREP Find

2009-08-19 Thread Warren Michelsen

At 1:36 PM -0400 8/19/09, Ronald J Kimball sent email regarding Re: 
Multi-line, Non-Greedy GREP Find:
>On Wed, Aug 19, 2009 at 10:24:29AM -0700, Warren Michelsen wrote:
>>
>>  How do I get this pattern to stop after finding the first "" tag? I
>>  want to replace  tags that span multiple lines.
>>
>>  ([\s\S]*)
>
>The simplest way is by using a non-greedy quantifier:
>
>([\s\S]*?)

I thought the non-greedy qualifier had to be associated with the 
close tag and therefore after the closing parentheses. I tried 
putting it all kinds of places, except inside the parentheses.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---