Re: Extract number within parentheses using GREP

2021-06-07 Thread Christopher Stone
On 06/07/2021, at 14:53, Christopher Stone  wrote:This becomes terribly tedious when you do it all by hand, so I wrote you an example Text Factory.Install here:~/Library/Application Support/BBEdit/Text Filters/Text Factories/You have to run it from the Text > Apply Text Filter menu with the target document FRONTMOST.Hey Howard,Oops...  I sent you the wrong Text Factory.  That one works but is less precise than this one.--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 here. 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 view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/2DFBE0DB-4D49-4C0A-802C-AE09B96D8396%40gmail.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 here. 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 view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/2DFBE0DB-4D49-4C0A-802C-AE09B96D8396%40gmail.com.


Re: Extract number within parentheses using GREP

2021-06-07 Thread Christopher Stone
On 06/03/2021, at 09:46, Howard  wrote:Chris, what you wrote is very helpful.To get the Grep results not enclosed in parentheses, I used the Replace pattern `\2` with this Search pattern:\d*(\((\d+)\))\d*but that resulted in these numbers:10161011Hey Howard,That can't be right.  If you genuinely got the above result you need to show all your steps.In BBEdit 12 and 13:Source:(10)0(16)500021(10)(11)Find: `\d*(\((\d+)\))\d*`Repl: `\2`Result:10161011The above would be better written this way:Source:(10)0(16)500021(10)(11)Find: `\d*\((\d+)\)\d*`Repl: `\1`Result:10161011To get the output you want add a space to `\1 `You'll get:10161011Follow that up by removing the trailing horizontal whitespace.Find: `\h+$`Repl: nothingThis becomes terribly tedious when you do it all by hand, so I wrote you an example Text Factory.Install here:~/Library/Application Support/BBEdit/Text Filters/Text Factories/You have to run it from the Text > Apply Text Filter menu with the target document FRONTMOST.Give it a keyboard shortcut for convenience in BBEdit's Menus & Shortcuts prefs.Text Factories let you do quite a lot without learning how to write scripts.--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 here. 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 view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/3480DA58-0FBC-4F72-99EC-9C25C868986E%40gmail.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 here. 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 view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/3480DA58-0FBC-4F72-99EC-9C25C868986E%40gmail.com.


Re: Extract number within parentheses using GREP

2021-06-03 Thread jj
Hi Howard, 

You can use this regex in the Find field:

\d*(?:\((\d+)\))?\d*(?:\((\d+)\))?\d*(?:\((\d+)\))?\d*(?:\((\d+)\))?\d*(?:\((\d+)\))?\d*

with this in the Replace field:

\1 \2 \3 \4 \5

It can find from 1 to 5 parentheses. Repeat the (?:\((\d+)\))?\d* pattern 
and the corresponding captures if you need more.

Here is a 2 parentheses case commented:

(?x)(?# allow whitespace and comments)
\d* (?# zero or more leading digits)
(?: (?# non capturing parenthesis)
\(  (?# literal open parenthesis)
(   (?# capturing open parenthesis - capture \1)
\d+ (?# one or more digits)
)   (?# capturing close parenthesis)
\)  (?# literal close parenthesis)
)?  (?# zero or one occurrence)
\d* (?# zero or more middle digits)
(?: (?# non capturing parenthesis)
\(  (?# literal open parenthesis)
(   (?# capturing open parenthesis - capture \2)
\d+ (?# one or more digits)
)   (?# capturing close parenthesis)
\)  (?# literal close parenthesis)
)?  (?# zero or one occurrence)
\d* (?# zero or more trailing digits)

You can copy this commented pattern and paste it "as is" in the Find dialog 
by right-clicking inside the "Find" field with the  pressed and 
choosing the "Paste and Select" menu item.

Regards,

Jean Jourdain

On Thursday, June 3, 2021 at 4:46:58 PM UTC+2 Howard wrote:

> Chris, what you wrote is very helpful.
>
> To get the Grep results not enclosed in parentheses, I used the Replace 
> pattern `\2` with this Search pattern:
>
> \d*(\((\d+)\))\d*
>
> but that resulted in these numbers:
> 10
> 16
> 10
> 11
>
> Given that the last two numbers, 10 and 11, are on the same line, is there 
> a way to modify the Grep expression so that the results appear with the 
> final two numbers on the same line, as shown below, with a space separating 
> them?
> 10
> 16
> 10 11
>
> Howard
>
>
> On Wednesday, 2 June 2021 at 5:37:42 am UTC-4 listmei...@gmail.com wrote:
>
>> On 06/01/2021, at 18:59, Howard  wrote:
>>
>> To help me to understand better the Grep part of Neil's solution, can 
>> someone provide me with the search pattern and the replace pattern to just 
>> find those lines with numbers in parentheses and extract them without 
>> any line numbers? I'd like to put that into the Pattern Playground and 
>> work with that a bit.
>>
>> --
>>
>> Hey Howard,
>>
>> Assuming all of your data lines are variations of this format:
>>
>> 1001405001
>> (10)
>> 00132001
>> 0(16)500
>> 021(10)(11)
>> 010101000
>>
>> Then it's extremely simple to extract the lines.
>>
>> Find:
>>
>> *.*\(\d+\).**
>>
>> .*   ==  any character zero or more.
>> \(   ==  literal open parenthesis.
>> \d+  ==  any digit one or more.
>> \)   ==  literal close parenthesis.
>> .*   ==  any character zero or more.
>>
>> --
>>
>> If I *knew* that any line containing even 1 parenthesis was viable for 
>> extraction I could be lazy and do:
>>
>> Find:
>>
>> *.*\(.**
>>
>> .*   ==  any character zero or more.
>> \(   ==  literal open parenthesis.
>> .*   ==  any character zero or more.
>>
>> OR
>>
>> You could use Neil's suggestion of Process-Lines-Containing with just 1 
>> literal parenthesis.
>>
>> --
>>
>> Now – to remove the unwanted digits:
>>
>> Find:
>>
>> *\d*(\(\d+\))\d**
>>
>> \d*  ==  any digit zero or more.
>> (==  start capture group.
>> \(   ==  literal parenthesis.
>> \d+  ==  any digit 1 or more.
>> \)   ==  literal parenthesis.
>> )==  close capture group.
>> \d*  ==  any digit zero or more.
>>
>> Replace:
>>
>> *\1*
>>
>> \1   ==  capture group 1.
>>
>> --
>>
>> As I've mentioned BBEdit is always my starting point for building regular 
>> expressions, but there are times when a tool like RegEx101.com will give 
>> you more information and more explanation.
>>
>> See your patter here:
>>
>> https://regex101.com/r/eUm1Fo/1
>>
>> --
>> Best Regards,
>> 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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/c6bcbe22-5996-4e58-a806-952ddedf84afn%40googlegroups.com.


Re: Extract number within parentheses using GREP

2021-06-03 Thread Howard
Chris, what you wrote is very helpful.

To get the Grep results not enclosed in parentheses, I used the Replace 
pattern `\2` with this Search pattern:

\d*(\((\d+)\))\d*

but that resulted in these numbers:
10
16
10
11

Given that the last two numbers, 10 and 11, are on the same line, is there 
a way to modify the Grep expression so that the results appear with the 
final two numbers on the same line, as shown below, with a space separating 
them?
10
16
10 11

Howard


On Wednesday, 2 June 2021 at 5:37:42 am UTC-4 listmei...@gmail.com wrote:

> On 06/01/2021, at 18:59, Howard  wrote:
>
> To help me to understand better the Grep part of Neil's solution, can 
> someone provide me with the search pattern and the replace pattern to just 
> find those lines with numbers in parentheses and extract them without any 
> line numbers? I'd like to put that into the Pattern Playground and work 
> with that a bit.
>
> --
>
> Hey Howard,
>
> Assuming all of your data lines are variations of this format:
>
> 1001405001
> (10)
> 00132001
> 0(16)500
> 021(10)(11)
> 010101000
>
> Then it's extremely simple to extract the lines.
>
> Find:
>
> *.*\(\d+\).**
>
> .*   ==  any character zero or more.
> \(   ==  literal open parenthesis.
> \d+  ==  any digit one or more.
> \)   ==  literal close parenthesis.
> .*   ==  any character zero or more.
>
> --
>
> If I *knew* that any line containing even 1 parenthesis was viable for 
> extraction I could be lazy and do:
>
> Find:
>
> *.*\(.**
>
> .*   ==  any character zero or more.
> \(   ==  literal open parenthesis.
> .*   ==  any character zero or more.
>
> OR
>
> You could use Neil's suggestion of Process-Lines-Containing with just 1 
> literal parenthesis.
>
> --
>
> Now – to remove the unwanted digits:
>
> Find:
>
> *\d*(\(\d+\))\d**
>
> \d*  ==  any digit zero or more.
> (==  start capture group.
> \(   ==  literal parenthesis.
> \d+  ==  any digit 1 or more.
> \)   ==  literal parenthesis.
> )==  close capture group.
> \d*  ==  any digit zero or more.
>
> Replace:
>
> *\1*
>
> \1   ==  capture group 1.
>
> --
>
> As I've mentioned BBEdit is always my starting point for building regular 
> expressions, but there are times when a tool like RegEx101.com will give 
> you more information and more explanation.
>
> See your patter here:
>
> https://regex101.com/r/eUm1Fo/1
>
> --
> Best Regards,
> 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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/976c251a-0da7-4520-b104-1566fd103201n%40googlegroups.com.


Re: Extract number within parentheses using GREP

2021-06-02 Thread Christopher Stone
On 06/01/2021, at 18:59, Howard mailto:leadwithlo...@gmail.com>> wrote:
> To help me to understand better the Grep part of Neil's solution, can someone 
> provide me with the search pattern and the replace pattern to just find those 
> lines with numbers in parentheses and extract them without any line numbers? 
> I'd like to put that into the Pattern Playground and work with that a bit.


Hey Howard,

Assuming all of your data lines are variations of this format:

1001405001
(10)
00132001
0(16)500
021(10)(11)
010101000

Then it's extremely simple to extract the lines.

Find:

.*\(\d+\).*

.*   ==  any character zero or more.
\(   ==  literal open parenthesis.
\d+  ==  any digit one or more.
\)   ==  literal close parenthesis.
.*   ==  any character zero or more.


If I knew that any line containing even 1 parenthesis was viable for extraction 
I could be lazy and do:

Find:

.*\(.*

.*   ==  any character zero or more.
\(   ==  literal open parenthesis.
.*   ==  any character zero or more.

OR

You could use Neil's suggestion of Process-Lines-Containing with just 1 literal 
parenthesis.


Now – to remove the unwanted digits:

Find:

\d*(\(\d+\))\d*

\d*  ==  any digit zero or more.
(==  start capture group.
\(   ==  literal parenthesis.
\d+  ==  any digit 1 or more.
\)   ==  literal parenthesis.
)==  close capture group.
\d*  ==  any digit zero or more.

Replace:

\1

\1   ==  capture group 1.


As I've mentioned BBEdit is always my starting point for building regular 
expressions, but there are times when a tool like RegEx101.com 
 will give you more information and more explanation.

See your patter here:

https://regex101.com/r/eUm1Fo/1 

--
Best Regards,
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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/95FE0CE0-CDBE-4044-A1CB-C4FAD1A7F1A2%40gmail.com.


Re: Extract number within parentheses using GREP

2021-06-01 Thread Tom Robinson
On 2021-06-02, at 11:59, Howard  wrote:
> 
> Thanks everyone for the responses. 
> 
> To help me to understand better the Grep part of Neil's solution, can someone 
> provide me with the search pattern and the replace pattern to just find those 
> lines with numbers in parentheses and extract them without any line numbers? 
> I'd like to put that into the Pattern Playground and work with that a bit.

Here’s the first one broken into components:

[0-9]   Search for a digit 0–9
*   Preceding search 0 or many times
(   Start a capture buffer
\(  Look for a literal left bracket (‘escape’ it)
[0-9]
+   Preceding search 1 or many times
\)  Look for a literal right bracket
)   End capture buffer
[0-9]
*

Note some of samples also used \d to search for digits.  Technically this can 
find them in other languages too.

-- 
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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/68E1AA75-C2DD-4D8F-B27F-7610851AA437%40gmail.com.


Re: Extract number within parentheses using GREP

2021-06-01 Thread Howard
Thanks everyone for the responses. 

To help me to understand better the Grep part of Neil's solution, can 
someone provide me with the search pattern and the replace pattern to just 
find those lines with numbers in parentheses and extract them without any 
line numbers? I'd like to put that into the Pattern Playground and work 
with that a bit.
On Tuesday, 1 June 2021 at 4:59:15 pm UTC-4 listmei...@gmail.com wrote:

> On 06/01/2021, at 08:11, Howard  wrote:
>
> I have a set of numbers. Within some of them is at least one number within 
> parentheses. I need to find all the lines containing numbers within 
> parentheses and extract those numbers. I also need to know which line they 
> are extracted from.
>
> --
>
> Hey Howard,
>
> Bash text filter:
>
> #!/usr/bin/env bash
> nl -n ln | sed -En 's![0-9]*(\([0-9]+\))[0-9]*!\1!p;'
>
> Result:
>
> 2 (10)
> 4 (16)
> 5 (10)(11)
>
> I've left on the parentheses to make it clear when there are more than one 
> set in a line.
>
>
> If we're going to resort to Perl we might as well go all in:
>
> #!/usr/bin/env perl -sw
> while (<>) {
>if ( m!\(\d+\)! ) {
>   s!\d*(\(\d+\))\d*!$1!g;
>   print "$.\t" . $_;
>}
> }
>
> Result:
>
> 2 (10)
> 4 (16)
> 5 (10)(11)
>
> Or just to be a bit cheeky:
>
> #!/usr/bin/env perl -sw
> while (<>) { if ( m!\(\d+\)! ) { s!\d*(\(\d+\))\d*!$1!g; print "$.\t" . $_; 
> } }
>
> OR
>
> #!/usr/bin/env bash
> perl -wlne '{if(m!\(\d+\)!){s!\d*(\(\d+\))\d*!$1!g;print"$.\t".$_;}}'
>
> 
>
> Don't forget – you can extract text directly from the front document using 
> the Find Dialog and the [Extract] button.
>
> 1) Number lines.
> 2) Extract lines to new doc (with Find Dialog).
> 3) Find/replace to leave only the desired text.
>
> The same as Neil's suggestion but without using *Process Lines Containing*
> .
>
> TMTOWTDI.
>
> I generally prefer using a text filter for this sort of thing, and I have 
> one that opens with a hotkey and runs via another hotkey. So writing a 
> filter and running it usually takes me less time than running through the 
> steps with BBEdit's other tools.  ( Usually but not always... :)
>
> --
> Best Regards,
> 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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/f1496960-4799-4146-ae84-15871e299c7fn%40googlegroups.com.


Re: Extract number within parentheses using GREP

2021-06-01 Thread Christopher Stone
On 06/01/2021, at 08:11, Howard mailto:leadwithlo...@gmail.com>> wrote:
> I have a set of numbers. Within some of them is at least one number within 
> parentheses. I need to find all the lines containing numbers within 
> parentheses and extract those numbers. I also need to know which line they 
> are extracted from.


Hey Howard,

Bash text filter:

#!/usr/bin/env bash
nl -n ln | sed -En 's![0-9]*(\([0-9]+\))[0-9]*!\1!p;'

Result:

2   (10)
4   (16)
5   (10)(11)

I've left on the parentheses to make it clear when there are more than one set 
in a line.


If we're going to resort to Perl we might as well go all in:

#!/usr/bin/env perl -sw
while (<>) {
   if ( m!\(\d+\)! ) {
  s!\d*(\(\d+\))\d*!$1!g;
  print "$.\t" . $_;
   }
}

Result:

2   (10)
4   (16)
5   (10)(11)

Or just to be a bit cheeky:

#!/usr/bin/env perl -sw
while (<>) { if ( m!\(\d+\)! ) { s!\d*(\(\d+\))\d*!$1!g; print "$.\t" . $_; } }

OR

#!/usr/bin/env bash
perl -wlne '{if(m!\(\d+\)!){s!\d*(\(\d+\))\d*!$1!g;print"$.\t".$_;}}'



Don't forget – you can extract text directly from the front document using the 
Find Dialog and the [Extract] button.

1) Number lines.
2) Extract lines to new doc (with Find Dialog).
3) Find/replace to leave only the desired text.

The same as Neil's suggestion but without using Process Lines Containing.

TMTOWTDI.

I generally prefer using a text filter for this sort of thing, and I have one 
that opens with a hotkey and runs via another hotkey. So writing a filter and 
running it usually takes me less time than running through the steps with 
BBEdit's other tools.  ( Usually but not always... :)

--
Best Regards,
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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/74CC204B-F53A-4EC0-8C2B-60CF212C16CE%40gmail.com.


Re: Extract number within parentheses using GREP

2021-06-01 Thread jj

Here is Neil 3 step process as one text filter

```sh
#!/usr/bin/env sh

perl -pe '$_ = "$.:$_"' | perl -ne 'print if /\(/' | perl -pe 
's/\d*\((\d*)\)\d*/ \1/g'
# add line number   # keep only lines containing a '(' # ouput only 
digits enclosed in parenthesis
```
Regards,

Jean Jourdain
On Tuesday, June 1, 2021 at 4:15:09 PM UTC+2 Neil Faiman wrote:

> On Jun 1, 2021, at 9:11 AM, Howard  wrote:
>
>
> I have a set of numbers. Within some of them is at least one number within 
> parentheses. I need to find all the lines containing numbers within 
> parentheses and extract those numbers. I also need to know which line they 
> are extracted from. How can I do that?
>
> Howard
>
> *Examples*
> 1001405001
> (10)
> 00132001
> 0(16)500
> 021(10)(11)
> 010101000
>
>
> There is likely a simpler way, but here is an easy three step process.
>
> 1. Text > Add/Remove Line Numbers... . Select “Insert”, check “Include 
> space after number”:
>
> 1 1001405001
> 2 (10)
> 3 00132001
> 4 0(16)500
> 5 021(10)(11)
> 6 010101000
>
>
> 2. Text > Process Lines Containing... . Search string “\(\d+\)”. Check 
> “Grep”, “Copy to new document”:
>
> 2 (10)
> 4 0(16)500
> 5 021(10)(11)
>
>
> 3. Command-F (or Search > Find). Search string “[ )]\d*\(?”. 
> Replacement string ” ” (a single space). Check “Grep”.Click “Replace All”.
>
> 2 10 
> 4 16 
> 5 10 11 
>
>
> In the result, each line contains a line number and one or more 
> parenthesized numbers, separated by spaces.
>
> Explanation of the grep search: You want to keep the initial line number 
> and the parenthesized numbers, and remove everything else, replacing it by 
> spaces. The search string is a description of an “everything else”:
>
> *“[ )]”– A*n “everything else” begins with a space (which must be the 
> space following the line number, since those are the only spaces in the 
> file) or the closing parenthesis of a parenthesized number.
> *“\d+”* — The string of contiguous digits following the space or closing 
> parenthesis are an “everything else” number.
> *“\(?”* — The “everything else” number is either at the end of the line 
> or it is followed by the opening parenthesis of a parenthesized number. So 
> if it is followed by an opening parenthesis, then that is part of the 
> “everything else”, too.
>
> Regards,
>
> Neil Faiman
>

-- 
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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/4a21cce3-bdc3-4a50-bb49-78008ceadaa7n%40googlegroups.com.


Re: Extract number within parentheses using GREP

2021-06-01 Thread Neil Faiman
On Jun 1, 2021, at 9:11 AM, Howard mailto:leadwithlo...@gmail.com>> wrote:
> 
> I have a set of numbers. Within some of them is at least one number within 
> parentheses. I need to find all the lines containing numbers within 
> parentheses and extract those numbers. I also need to know which line they 
> are extracted from. How can I do that?
> 
> Howard
> 
> Examples
> 1001405001
> (10)
> 00132001
> 0(16)500
> 021(10)(11)
> 010101000

There is likely a simpler way, but here is an easy three step process.

1. Text > Add/Remove Line Numbers... . Select “Insert”, check “Include space 
after number”:

1 1001405001
2 (10)
3 00132001
4 0(16)500
5 021(10)(11)
6 010101000

2. Text > Process Lines Containing... . Search string “\(\d+\)”. Check “Grep”, 
“Copy to new document”:

2 (10)
4 0(16)500
5 021(10)(11)

3. Command-F (or Search > Find). Search string “[ )]\d*\(?”. Replacement 
string ” ” (a single space). Check “Grep”.Click “Replace All”.

2 10 
4 16 
5 10 11 

In the result, each line contains a line number and one or more parenthesized 
numbers, separated by spaces.

Explanation of the grep search: You want to keep the initial line number and 
the parenthesized numbers, and remove everything else, replacing it by spaces. 
The search string is a description of an “everything else”:

“[ )]”– An “everything else” begins with a space (which must be the space 
following the line number, since those are the only spaces in the file) or the 
closing parenthesis of a parenthesized number.
“\d+” — The string of contiguous digits following the space or closing 
parenthesis are an “everything else” number.
“\(?” — The “everything else” number is either at the end of the line or it is 
followed by the opening parenthesis of a parenthesized number. So if it is 
followed by an opening parenthesis, then that is part of the “everything else”, 
too.

Regards,

Neil Faiman

-- 
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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/D28DAE4F-2B5B-4A9F-98BD-24538B6BD750%40faiman.org.


Extract number within parentheses using GREP

2021-06-01 Thread Howard
I have a set of numbers. Within some of them is at least one number within 
parentheses. I need to find all the lines containing numbers within 
parentheses and extract those numbers. I also need to know which line they 
are extracted from. How can I do that?

Howard

*Examples*
1001405001
(10)
00132001
0(16)500
021(10)(11)
010101000

-- 
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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/c1dda7c4-7f4f-4765-a943-e4b106933df8n%40googlegroups.com.