Re: Asking the experts for a less greedy regex

2019-06-23 Thread Patrick Woolsey
On Jun 22, 2019, at 18:41, Christopher Stone  wrote:
> 
> On 06/22/2019, at 14:15, Patrick Woolsey  wrote:
>> Based on your description above, I expect something like this should do the 
>> job, or at least serve as a starting point for further experimentation :-):
>> 
>> Search for:(( |)if \(.+?!=.+?$)
> 
> Hey Patrick,
> 
> I expect I'd normally write that like this:
> 
> (\h?if \(.+?!=.+?$)
> 
> Is there any advantage to “( |)” other than being readable?

None of which I'm aware; that was mainly reflexive on my part. :-)


Regards,

 Patrick Woolsey
==
Bare Bones Software, Inc. 

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/46440C81-B465-49FC-A977-390176DD4B89%40barebones.com.


Re: Asking the experts for a less greedy regex

2019-06-22 Thread Christopher Stone
On 06/22/2019, at 14:15, Patrick Woolsey mailto:pwool...@barebones.com>> wrote:
> Based on your description above, I expect something like this should do the 
> job, or at least serve as a starting point for further experimentation :-):
> 
> Search for:(( |)if \(.+?!=.+?$)


Hey Patrick,

I expect I'd normally write that like this:

(\h?if \(.+?!=.+?$)

Is there any advantage to “( |)” other than being readable?


--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/34CB26E6-EF37-4943-A626-32989B4A0141%40suddenlink.net.


Re: Asking the experts for a less greedy regex

2019-06-22 Thread F. Alfredo Rego
Thanks, Patrick.

Alfredo

> On Jun 22, 2019, at 1:15 PM, Patrick Woolsey  wrote:
> 
> On Jun 22, 2019, at 13:03, F. Alfredo Rego  wrote:
>> 
>> I’m interested in finding “if” statements that contain the negation operator 
>> “!” (or potentially several negation operators) anywhere, regardless of 
>> blank lines, parentheses, indentation, and so on.
>> 
>> My motivation is to verify, one by one, the scope(s) of the negation(s).
>> 
>> For instance, considere this code snippet:
>> 
>> if ( ID ==   OK_ID )OK_ID_procedure (ID);
>>else if ( ID == fake_ID )  fake_ID_procedure (ID);
>>else if ( ID ==  old_ID )   old_ID_procedure (ID);
>>else if ( ID != lost_ID ) check_ID_procedure (ID);
>> 
>> 
>> I would like to select JUST THE LAST “if” statement, which is the only one 
>> that contains the negation operator, like so:
>> 
> 
> Based on your description above, I expect something like this should do the 
> job, or at least serve as a starting point for further experimentation :-):
> 
> Search for:(( |)if \(.+?!=.+?$)
> 
> 
>> The best I have done, so far, is this regex, with a space as its first 
>> character to ignore #ifdef and such: 
>> if(?s).+?\(.*?!.*?(;|\{)
> 
> Since (?s) enables . to match _across_ hard line breaks, you probably do not 
> want to use it here since that's why the above pattern is matching the whole 
> snippet.
> 
> 
> Regards,
> 
> Patrick Woolsey
> ==
> Bare Bones Software, Inc. 
> 
> -- 
> This is the BBEdit Talk public discussion group. If you have a 
> feature request or need technical support, please email
> "supp...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter: 
> --- 
> 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 bbedit+unsubscr...@googlegroups.com.
> To post to this group, send email to bbedit@googlegroups.com.
> Visit this group at https://groups.google.com/group/bbedit.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/bbedit/F4F3F31D-1D95-4947-A536-DAB806BE2FB4%40barebones.com.

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/2FA90AD6-0870-4499-9CD8-B43714CCB151%40gmail.com.


Re: Asking the experts for a less greedy regex

2019-06-22 Thread Patrick Woolsey
On Jun 22, 2019, at 13:03, F. Alfredo Rego  wrote:
> 
> I’m interested in finding “if” statements that contain the negation operator 
> “!” (or potentially several negation operators) anywhere, regardless of blank 
> lines, parentheses, indentation, and so on.
> 
> My motivation is to verify, one by one, the scope(s) of the negation(s).
> 
> For instance, considere this code snippet:
> 
>  if ( ID ==   OK_ID )OK_ID_procedure (ID);
> else if ( ID == fake_ID )  fake_ID_procedure (ID);
> else if ( ID ==  old_ID )   old_ID_procedure (ID);
> else if ( ID != lost_ID ) check_ID_procedure (ID);
> 
> 
> I would like to select JUST THE LAST “if” statement, which is the only one 
> that contains the negation operator, like so:
> 

Based on your description above, I expect something like this should do the 
job, or at least serve as a starting point for further experimentation :-):

Search for:(( |)if \(.+?!=.+?$)


> The best I have done, so far, is this regex, with a space as its first 
> character to ignore #ifdef and such: 
>  if(?s).+?\(.*?!.*?(;|\{)

Since (?s) enables . to match _across_ hard line breaks, you probably do not 
want to use it here since that's why the above pattern is matching the whole 
snippet.


Regards,

 Patrick Woolsey
==
Bare Bones Software, Inc. 

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/F4F3F31D-1D95-4947-A536-DAB806BE2FB4%40barebones.com.


Asking the experts for a less greedy regex

2019-06-22 Thread F. Alfredo Rego
Hello Regex gurus,

I’m interested in finding “if” statements that contain the negation operator 
“!” (or potentially several negation operators) anywhere, regardless of blank 
lines, parentheses, indentation, and so on.

My motivation is to verify, one by one, the scope(s) of the negation(s).

For instance, considere this code snippet:

 if ( ID ==   OK_ID )OK_ID_procedure (ID);
else if ( ID == fake_ID )  fake_ID_procedure (ID);
else if ( ID ==  old_ID )   old_ID_procedure (ID);
else if ( ID != lost_ID ) check_ID_procedure (ID);


I would like to select JUST THE LAST “if” statement, which is the only one that 
contains the negation operator, like so:





The best I have done, so far, is this regex, with a space as its first 
character to ignore #ifdef and such: 
 if(?s).+?\(.*?!.*?(;|\{)

It works well but it produces too many “false positives” through which I need 
to wade. 

This regex selects everything from the first “if” in this snippet to the last 
semicolon:




No big deal, but I thought I would ask the experts for a less greedy regex. 

I tried several possible non-greedy options but they produced 
unexpected/undesirable secondary effects.

Thanks for any hints.

Alfredo

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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 bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/10B4C319-FAFF-4CEA-A582-5536E5CF016D%40gmail.com.