• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Help with a GREP to find only first match in a paragraph.

Participant ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

Hi

 

I need a GREP to fix a space problem in a book, I want to change the first ( - ) in the paragraph to ( -) and the second to (- ), so I should do it in two steps but the grep applies the first step to the all the ( - ).

The GREP I tried:

( - )?

 

TOPICS
How to , Type

Views

505

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 2 Correct answers

Community Expert , May 19, 2022 May 19, 2022

Try the following

Find What
(\( - \))(.*?)(\( - \))
Change to
( -)$2(- )

-Manan 

Votes

Translate

Translate
Community Expert , May 19, 2022 May 19, 2022

So you want to change English/Dutch spaced dashes to French/Spanish/etc. 'semi-spaced' dashes. Assuming that all your space dashes are those that you're after, you could try these two expressions.

 

The opening dashes (I used \x20 for the space character so that you can see it)

 

Find what: \x20-\x20(?=.+?\x20-\x20)
Change to: \x20-

 

Then do the closing dashes:

 

Find what: \x20-[^\x20].+\K\x20-\x20
Change to: -\x20

P

Votes

Translate

Translate
Community Expert ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

Try the following

Find What
(\( - \))(.*?)(\( - \))
Change to
( -)$2(- )

-Manan 

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
Participant ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

Thank you, Manan.

That did it after adjusting it to not include parentheses.

 

so it looks like this:

Find:

( - )(.*?)( - )

 

change to:

-$2-

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
Community Expert ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

Hi @AK09M,

Look at the first post that @Peter Kahrel made. That should be the way to go. My method could cause issues as shown by another post by Peter. You can chain the two search replace operations into one by using the FindChangeList script shipped with InDesign and that way just a single click should do all the edits for you.

-Manan

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
Community Expert ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

So you want to change English/Dutch spaced dashes to French/Spanish/etc. 'semi-spaced' dashes. Assuming that all your space dashes are those that you're after, you could try these two expressions.

 

The opening dashes (I used \x20 for the space character so that you can see it)

 

Find what: \x20-\x20(?=.+?\x20-\x20)
Change to: \x20-

 

Then do the closing dashes:

 

Find what: \x20-[^\x20].+\K\x20-\x20
Change to: -\x20

P

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
Community Expert ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

@Manan Joshi -- I think the parentheses in the example are just to show the spaces before the dashes. But anyway, unfortunately, doing a replacement like you suggest makes a bash of any formatting.

P.

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
Community Expert ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

Hi @Peter Kahrel, thanks for sharing your thoughts. Apart from the parentheses, I did a quick test before sharing the regex and found that changes in properties like stroke color, or font were properly preserved when the change was made using my grep search and replace. However, I do understand your point.

-Manan

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
Community Expert ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

Well. . . Before and after:

PeterKahrel_0-1652968200402.png

 

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
Community Expert ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

Hi @Peter Kahrel,

See the video given below

Any idea why the formatting I used are not getting messed up.

-Manan

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
Community Expert ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

Hi @Manan Joshi -- I've no idea why it works in your video. Are those characters outlined? Then it makes sense that it works. I tried with some other formats, and the shifts happen in every case:

PeterKahrel_0-1653042168428.png

Underline, bold, a colour, a condition, and a font+G stroked.

P.

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
Community Expert ,
May 22, 2022 May 22, 2022

Copy link to clipboard

Copied

LATEST

Nothing special with the text. I just used fill with palceholder text, added the local overrides and the ran the Grep find/replace. Anyhow your point is well recieved and hopefully the OP will pay heed to your suggestion.

-Manan

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