• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Grep repeat matches using negative lookahead and subexpressions

New Here ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

I have been tasked with making a bunch of documents made in an old clunky piece of software into Indesign files. The old software makes all line shifts full returns (some of which have extra spaces in front and behind them), and things that are supposed to be real returns are just double returns. Also it's intersperced with double spaces. It's a whole mess.

I wanna just be able to press "change all" in the story and have these things be largely fixed, so I came up with (|\s+)\r(|\s+)(?!\r)|\s{2,} to replace all my problems with a space.

It almost does everything I want it to do. Problem is, as soon as I add any other variables other than \r and (?!\r) it starts matcing repeating returns, which of course would remove the returns I actually need.

 

Skærmbillede 2021-08-06 104715.pngSkærmbillede 2021-08-06 104254.png

I've been trying a bunch of iterations where I don't include the plus, do different hierarchies and systematically removed and isolated several parts of it, and it always ends up matching repeating returns unless it's \r(?!\r).

 

Can someone tell me what I'm doing wrong?

TOPICS
How to

Views

194

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 06, 2021 Aug 06, 2021

I think it might be easier to do it in steps.

 

One way to deal with the double returns is to find them and replace with something else that would not otherwise occur, say [ZZZ]. then at the end you can find /[ZZZ/] and replace with a return.

Votes

Translate

Translate
Community Expert ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

I think it might be easier to do it in steps.

 

One way to deal with the double returns is to find them and replace with something else that would not otherwise occur, say [ZZZ]. then at the end you can find /[ZZZ/] and replace with a return.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

LATEST

I ended up modifying the "findChangeByList" script using your trick.

Works like a charm!

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines