6 Replies Latest reply on Apr 19, 2013 1:12 AM by Peter Kahrel

# GREP: Find multiple paragraphs between brackets

Attempting to write a grep that will find text, including paragraph breaks, between bracketed tags [EXT] and [/EXT].  It looks like this:

Int hillestisite militam dolupta corera seque nonsers perrum aut aut por aut et et earum dolorio dolut re

[EXT] m doluptae dolorem idebit pa dolendit, optassi mendae optam labor sita consecum

conet ere, nihil etum sa conem dolessim rehenisquam con pos eatem ipistio odit acienetur ratis dolupti orenim et inveni officati undi reium faccae. Pienistecae n[/EXT]

[EXT]onsed et aliciae plabor aut mos qui tem nobis quatis denihil latusantin estion recte explaborem ent quist, solest, omniendaecto bersperro dolest, volene sam autatur, volupta tiossit ab imuscia epernature et alitatuscia qui niendant que ne qu

atiassit, et pa ditati res dolent, cum estis eatempo rerovid elenis nis volecu

mquam quo eumet quis dolupta voles dollantium a quidi doloriori officilis mintior entini unt quo eost ma doluptiorro ea

quibus a et fugiatibus excepuditi cus utecus moditatem consequ atemoditia doluptat dolum quos res doluptibus arum fu[/EXT]

ga. Nam, quis minullor adignita soluptias etus sit quam quis am vendiciis alit ero eliq

Here's my formula:

\[EXT](.+\r.+)+\[/EXT]

It will find the second set of brackets, the one with multiple paragraph breaks, but won't find the first set, the one with only a single paragraph break.

Any ideas?

Thanks!

• ###### 1. Re: GREP: Find multiple paragraphs between brackets

It's as simple as last one.

Try this:

```\[EXT\][^\]]+\[\/EXT\]
```

Hope that helps.

--

Marijan (tomaxxi)

http://tomaxxi.com

• ###### 2. Re: GREP: Find multiple paragraphs between brackets

Thank you!  I'm looking at it, and don't fully understand it.  [^\]]+ must mean to find everything inbetween?

• ###### 3. Re: GREP: Find multiple paragraphs between brackets

Explanation: find every character one or more time EXCEPT right square bracket.

--

Marijan (tomaxxi)

• ###### 4. Re: GREP: Find multiple paragraphs between brackets

Matthew,

. doesn't match paragraph marks. You tried to use (.+\r.+)+ to get around that, but that's not going to work. There are two easy ways to get around that. One method is the one Marijan used: [^[]+ continues matching up to the next [, no matter what characters intervene, so it skips paragraph breaks. [^x] (where 'x' stands for any chancter) is a negative character class, so that [^x]+ can be read as 'while not x'.

The second method is to tell grep to treat the whole story as a single line:

(?s)\[EXT\].+?\[\/EXT\]

where .+? stands for 'shortest match'.

Peter

• ###### 5. Re: GREP: Find multiple paragraphs between brackets

This is great I've been using this

Find: (?s)<CC>(.+?)<\/CC>

Change: \$1

Couple of thing though more for my sanity then anything else...

If whetever is inbetween () is a copied then why is it that (?s) is ignored but the \$1, and only replaces with the second instance of () which I would have thought would have been \$2

Also This Grep falls over if there is a Table in the paragraph, is there a way to to ignore the table as I would have thought the table would be treated as text

• ###### 6. Re: GREP: Find multiple paragraphs between brackets

There are various so-called non-capturing modifiers: (?s), (?i), etc. And even capturing parentheses can be made non-capturing if you just want to group something. E.g. (this|that)? captures all this and that, but if you want to test for the presence of this or that without any need to capture any of them, you use (?:this|that)?

Tables are a problem, they're one of those things that . doesn't match. Footnotes are another one, though you can get around them somehow. Tables appear to be an absolute break. Please file a bug against that at http://www.adobe.com/misc/bugreport.html

Peter