GREP to find a sequence of characters without a closing apostrophe

394 Views Asked by At

I'm trying to find long quotes in the text that I'm editing so that I can apply a different style to them. I've tried this GREP:

~[.{230}(?!.~])

What I need is for the GREP to find any 230 characters preceded by a left/opening quote mark, not including any 230-character sequence including a character followed by a right/clsoing quote mark. This should then eliminate quotes of less than 230 characters from the search. My GREP finds the correct length sequence but doesn't exclude those sequences which include a right quote mark.

So I want to find this, which my GREP does:

enter image description here

But not this, which my GREP also finds:

enter image description here

Because it has a closing quote in it and is therefore what I'm classing as a short quote.

Any ideas? TIA

2

There are 2 best solutions below

0
On BEST ANSWER

You can match an opening followed by 230 or more occurrences of any character except an opening or closing quotation mark.

To not match the closing quotation mark, you can assert it using a positive lookahead.

‘[^‘’]{230,}(?=’)
  • Match
  • [^‘’]{230,} Repeat 230+ times any char except or using a negated character class
  • (?=’) Positive lookahead, assert directly to the right

See a regex demo.

1
On

Thanks @Thefourthbird.

So what I needed was:

‘[^’]{230,}

to search for an opening apostrophe ‘ followed by anything but a closing apostrophe [^’] of 230 characters or more {230,}

Strangely, if you use InDesign's code for left ~[ and right ]~ apostrophe it doesn't work!