Skip to main content
Participating Frequently
June 19, 2021
Answered

Interrupted list

  • June 19, 2021
  • 1 reply
  • 699 views

I have a situation where I have to use regular expressions Grep to find and replace successfully some peculiar strings, as seen below:

 

I have this kind of dummy text:

"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed semper scelerisque fermentum. Mauris fringilla et massa Abc 2:5a; 24:51d, 53; 1:9b, 22-23; 1:22-23c, 9; 1:22-23, 24-25; eget congue. Aenean erat ligula, dapibus risus fringilla, malesuada ultricies ligula. Nam sit amet dignissim urna. Nunc efficitur tincidunt erat, sed interdum lacus vehicula in. Suspendisse ornare, dui ut scelerisque, vel egestas justo nisi a turpis efficitur. Praesent consectetur augue id consectetur condimentum. Morbi sagittis, sem sit amet dapibus varius, elit dolor sodales ex, amet risus diam eget nisi. (Def 2:5a; 24:51d, 53; 1:9b, 22-23; 1:22-23c, 9; 1:22-23, 24-25) Mauris quis lorem vehicula, venenatis lectus et, venenatis elit. Pellentesque facilisis vitae quam at ullam corper Integer arcu ex, ultrices ut mauris a, interdum lobortis nibh. Nullam placerat id mi sit amet posuere. Cras tincidunt commodo aliquam. Mauris auctor dolor in nulla feugiat aliquam.

Nulla facilisi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed semper scelerisque fermentum. Mauris fringilla et massa eget congue. Aenean erat ligula, dapibus cursus risus fringilla, malesuada ultricies ligula. Nam sit amet dignissim urna. Nunc efficitur tincidunt erat, sed interdum lacus vehicula in. Suspendisse ornare, dui ut scelerisque fringilla, augue mi scelerisque libero, vel justo nisi (3Gh 2:5a; 24:51d, 53; 1:9b, 22-23; 1:22-23c, 9; 1:22-23, 24-25) . Praesent consectetur augue id consectetur condimentum. Morbi sagittis, sem sit amet dapibus varius, elit dolor sodales ex, sit amet risus. Mauris quis lorem vehicula, venenatis lectus et, venenatis elit. Pellentesque facilisis vitae quam 3Mo 2:5a; 24:51d, 53; 1:9b, 22-23; 1:22-23c, 9; 1:22-23, 24-25; at ullamcorper. Integer arcu ex, ultrices ut mauris a, interdum lobortis nibh. Nullam placerat id mi sit amet posuere. Cras tincidunt commodo aliquam. Mauris auctor dolor in nulla feugiat aliquam. Nulla facilisi."


I have to Find via Grep these strings in their paragraphs:
text before Abc 2:5a; 24:51d, 53; 1:9b, 22-23; 1:22-23c, 9; 1:22-23, 24-25;
text before (Def 2:5a; 24:51d, 53; 1:9b, 22-23; 1:22-23c, 9; 1:22-23, 24-25)
text before (3Gh 2:5a; 24:51d, 53; 1:9b, 22-23; 1:22-23c, 9; 1:22-23, 24-25)
text before 3Mo 2:5a; 24:51d, 53; 1:9b, 22-23; 1:22-23c, 9; 1:22-23, 24-25;

 

And I need them to be Replaced with these in their respective paragraphs:
text before Abc 2:5a; Abc 24:51d, 53; Abc 1:9b, 22-23; Abc 1:22-23c, 9; Abc 1:22-23, 24-25;
text before (Def 2:5a; Def 24:51d, 53; Def 1:9b, 22-23; Def 1:22-23c, 9; Def 1:22-23, 24-25)
text before (3Gh 2:5a; 3Gh 24:51d, 53; 3Gh 1:9b, 22-23; 3Gh 1:22-23c, 9; 3Gh 1:22-23, 24-25)
text before 3Mo 2:5a; 3Mo 24:51d, 53; 3Mo 1:9b, 22-23; 3Mo 1:22-23c, 9; 3Mo 1:22-23, 24-25;

 

Note that:
1. All the strings are in the middle of their respective pragraph, not at the beginning.
2. Two strings (yellow and purple) start with a digit. See picture below.

3. The small letter (a or b or etc) within the to be found strings, may be or may not be there.

 

Thank you all very much for your help.

Dumitru S.

 

 

 

 

 
 
 
 
 
This topic has been closed for replies.
Correct answer Peter Kahrel

I believe Peter Kahrel has posted a script on his web page for chaining multiple find/change queries.


Indeed. And all tarted up recently: https://creativepro.com/files/kahrel/indesign/grep_query_runner.html

 

1 reply

Community Expert
June 20, 2021

I think you can find them all with a GREP expression.

 

But i don't think it would be possible to place ABC in front of just ABC

And I don't think it would be possible to place just DEF just in the line for DEF.

 

There woudln't be a function for it. 

 

The best you can do is find where they are and manually place them.

 

Just need to ask - is it just these 4 expressions? Or are there more?

It might be doable with a  script but I'm not a scripter.

Participating Frequently
June 20, 2021

There are more than these 4 expressions.

And Yes, it is true that a script might do it.

Peter Spier
Community Expert
Community Expert
June 20, 2021

I believe Peter Kahrel has posted a script on his web page for chaining multiple find/change queries.