Regex to get lines starting with digits, and all between round bracket on any line
-
1. A New Relationship. He appeared first to Mary Magdalene (Mark 16:9). The details of this first appearing are given in (John 20:1–18). Mary illustrates the position of the saints of this present time—the heavenly saints. 2. The Kingdom. To the devoted company of women of Galilee (Matt. 28:9). They are a figure of the earthly saints. He says nothing of His ascension to the Father, nor does He refuse their touching Him. 3. Christ’s present ministry on high as Advocate. To Peter (Luke 24:34 and 1 Cor. 15:5). Peter had grievously sinned and lost all communion with God. He needed restoration. “If any man sin, we have an Advocate with the Father, Jesus Christ the righteous” (1 John 2:1). 4. Christ’s present ministry on high as Priest. To the two disciples on their way to Emmaus (Luke 24:13–32). What is here illustrated, as well as in the former appearing, tells of the present ministry of our Lord now on high, for His people down here. 5. The Church, a new Company. To the company in the upper room at Jerusalem, on the first Lord’s Day evening (John 20:19–23 and Luke 24:36–43). 6. A new Nation. To the eleven, in the upper room at Jerusalem, on the second Lord’s Day evening (John 20:24–31). In the Lord’s dealing with Thomas on this occasion, we have an illustration of the repentance and restoration of the Jewish remnant
I wish to use a Regex to get lines starting with digits, and just the chars between round bracket on any other line. Note, there could be more than one set of brackets on some lines.
The lines starting with digits works fine. But I am trying to use non-capture groups to eliminate content before and after the bracketed content. So "non-capture start of line to first “(” , then capture content to “)” , then non-capture to second “(” if there is one, then capture content to “)” and so on to end of line. I will keep trying, but if anyone could help it would be much appreciated. Thanx,^\d.*$|^(?:.*?\()(.*?\))(?:.*?$)
Bob
Edit by moderator
-
Your request is pretty hard for me to parse. It would probably be easier for people to help you if you actually gave a list of the substrings you want to match in the example you gave us.
-
Hello, @Robert-or-Janet-Diebel, @mark-olson and All,
Well, here is my solution. So, giving your INPUT test :
1. A New Relationship. He appeared first to Mary Magdalene (Mark 16:9). The details of this first appearing are given in (John 20:1–18). Mary illustrates the position of the saints of this present time—the heavenly saints. 2. The Kingdom. To the devoted company of women of Galilee (Matt. 28:9). They are a figure of the earthly saints. He says nothing of His ascension to the Father, nor does He refuse their touching Him. 3. Christ’s present ministry on high as Advocate. To Peter (Luke 24:34 and 1 Cor. 15:5). Peter had grievously sinned and lost all communion with God. He needed restoration. “If any man sin, we have an Advocate with the Father, Jesus Christ the righteous” (1 John 2:1). 4. Christ’s present ministry on high as Priest. To the two disciples on their way to Emmaus (Luke 24:13–32). What is here illustrated, as well as in the former appearing, tells of the present ministry of our Lord now on high, for His people down here. 5. The Church, a new Company. To the company in the upper room at Jerusalem, on the first Lord’s Day evening (John 20:19–23 and Luke 24:36–43). 6. A new Nation. To the eleven, in the upper room at Jerusalem, on the second Lord’s Day evening (John 20:24–31). In the Lord’s dealing with Thomas on this occasion, we have an illustration of the repentance and restoration of the Jewish remnant
the following regex S/R :
-
FIND
(?-s)^\d.*\R.*?\((.*?)\).*\R
-
REPLACE
\1\r\n
Would get the *OUTPUT text below :
Mark 16:9 Matt. 28:9 Luke 24:34 and 1 Cor. 15:5 Luke 24:13–32 John 20:19–23 and Luke 24:36–43 John 20:24–31
If you want to keep the parentheses, use the following S/R :
-
FIND
(?-s)^\d.*\R.*?(\(.*?\)).*\R
-
REPLACE
\1\r\n
(Mark 16:9) (Matt. 28:9) (Luke 24:34 and 1 Cor. 15:5) (Luke 24:13–32) (John 20:19–23 and Luke 24:36–43) (John 20:24–31)
Best Regards,
guy038
-
-
Hi, @Robert-or-Janet-Diebel, @mark-olson and All,
Oh…, I forgot that you said :
Note, there could be more than one set of brackets on some lines
Of course, this statement change the global search regex ! In order to not use capture group for each part
(........)
to keep, we’ll use the opposite logic :-
If an expression is between parentheses, it will be ignored
-
Any line beginning with a digit or any string without parenthesis will be deleted
This leads to this new regex S/R :
-
FIND
(?-s)\(.+?\)(*SKIP)(*F)|^\d.*\R|[^()\r\n]+
-
REPLACE
Leave EMPTY
Example :
From this INPUT text
1. bla blah This is (a test) of some text ( to verify ) if (it works) nicely !
You would be left with this OUTPUT text :
(a test)( to verify )(it works)
Best Regards,
guy038
-
-
@guy038 Thanx much for your help