On Jun 1, 2021, at 9:11 AM, Howard <[email protected] 
<mailto:[email protected]>> 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
> 0000(10)0000
> 001320000001
> 0(16)5000000
> 021(10)0000(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 0000(10)0000
3 001320000001
4 0(16)5000000
5 021(10)0000(11)
6 010101000

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

2 0000(10)0000
4 0(16)5000000
5 021(10)0000(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 "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/D28DAE4F-2B5B-4A9F-98BD-24538B6BD750%40faiman.org.

Reply via email to