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

Explorer ,
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

122

Likes

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

Adobe Community Professional , May 19, 2022 May 19, 2022
Try the following Find What (\( - \))(.*?)(\( - \)) Change to ( -)$2(- ) -Manan 

Likes

Translate

Translate
Adobe Community Professional , 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

Likes

Translate

Translate
Adobe Community Professional ,
May 19, 2022 May 19, 2022

Copy link to clipboard

Copied

Try the following

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

-Manan 

Likes

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
Explorer ,
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-

Likes

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
Adobe Community Professional ,
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

Likes

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
Adobe Community Professional ,
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

Likes

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
Adobe Community Professional ,
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.

Likes

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
Adobe Community Professional ,
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

Likes

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

Copy link to clipboard

Copied

Well. . . Before and after:

PeterKahrel_0-1652968200402.png

 

Likes

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
Adobe Community Professional ,
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

Likes

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
Adobe Community Professional ,
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.

Likes

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
Adobe Community Professional ,
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

Likes

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