Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Can GREP re-arrange text?

Community Beginner ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

Hello, I'm working on a big catalogue project. The data underneath each book is already there in the old designer's files, but my client wants to change the order in which the text is seen. I have felt very clever this morning for discovering GREP and I've managed to get it to apply a specific character style to words inbetween parantheses with \((.*?)\) but re-arranging text is just so far beyond me. With a tight deadline, I do not have the time to learn GREP right now and I'm hoping someone can help me out with this.

 

The current text is like this:

Book Name

ISBN

Additional info

 

Real example:

Ready for Reading Phonics (Wipe-Clean)
9781474 93694 1
Age 4+ | Gareth Williams

Repeated over and over. They are separated with a new column break at the end of the book title before the next ISBN starts at the top of the next column (except of course the last book in the last column) of that text box.

 

What I need it to look like is:

9781474 93694 1
Age 4+ | Gareth Williams

Ready for Reading Phonics (Wipe-Clean)

 

Rather than cutting the book title from the top line and pasting it to be the bottom line thousands of times, I'm hoping there might be some GREP code which can just do it for me?

Sometimes the ISBN has a price on the same line as it, and I need the price to get cut off and put on a new line. And sometimes there is no extra information under the ISBN, it would just be ISBN, paragraph break, Book Title. However... if that is too complicated just being able to have the book titles automatically moved to be underneath everything else would save me from doing that particular cut and paste a few thousand times.

 

9781474 93694 1 $11.95
Age 4+ | Gareth Williams

I need to be:

9781474 93694 1
$11.95 | Age 4+ | Gareth Williams

 

I have become aware that the | means "or" in GREP. Here I am using it as a visual separator.

 

Pehaps due to my lack of understanding of GREP this is not something that it can do. But if it can... oh my word would this save me hours and hours of work.

TOPICS
How to, Type

Views

168

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

Adobe Community Professional , Oct 16, 2021 Oct 16, 2021
For changing Ready for Reading Phonics (Wipe-Clean) 9781474 93694 1 Age 4+ | Gareth Williams to 9781474 93694 1 Age 4+ | Gareth Williams Ready for Reading Phonics (Wipe-Clean) Try the following Grep/Change string in the Find/Change dialog Find What (.+)\r(.+)\r(.+)(\r?) Change to $2\r$3\r$1$4 -Manan 

Likes

Translate

Translate
Adobe Community Professional , Oct 17, 2021 Oct 17, 2021
Like Manan Joshi I've been unable to come up with a GREP solution that I think will work for you without a very rigid data structure. I'm not a scripter, unfortunately, but I do think this is probably scriptable, particularly if you have assigned paragraph styles to the different types of paragraphs (different style for ISBN, Title, and Other info) which would allow a script to identify when paragraphs are missing, as well as to kick the price out and add it to the following line. You don't ha...

Likes

Translate

Translate
Adobe Community Professional , Oct 17, 2021 Oct 17, 2021
The GREP query to remove trailing white space from any paragraph is Find: \s+$ and leave the change field blank. That's something I usually run early on in any editing project. You could use Find: (?<=\d{7}\s)\d{5}\s\d to find the last 6 didgits of an ISBN regardless of waht comes before or after it. This uses a Positive Lookbehind (click the little @ symbol next to the find filed and you'll see Match in the dropdown where you can choose positive or negative look ahead or behind) to match five...

Likes

Translate

Translate
Advocate ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

Hello @rachaelc29879128 

 

Did you try using the Find\Chage text option?

 

Regards,

Mike

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
Community Beginner ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

Hi Mike, thank you for taking the time to read my post and respond!

I'm sorry I do not understand.

What would I put into the Find/Change text dialogue to get it to switch around the order of the lines of text?

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 ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

There are tabs in the Find/Change dialog for Text, Grep search etc. Switch to the Grep tab and use the entries I gave to give it a shot. To open the Find/Change dialog use Cmd+F on MAC or Ctrl+F on WIN

-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 ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

For changing

Ready for Reading Phonics (Wipe-Clean)
9781474 93694 1
Age 4+ | Gareth Williams

to

9781474 93694 1
Age 4+ | Gareth Williams

Ready for Reading Phonics (Wipe-Clean)

Try the following Grep/Change string in the Find/Change dialog

Find What

(.+)\r(.+)\r(.+)(\r?)

Change to

$2\r$3\r$1$4

-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
Community Beginner ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

Hello Manan,

Wow that is really impressive! It was fantastic to watch the lines of text get moved around. Unfortunately what ended up happening was that it rearranged my test text box with four books in it to become:

ISBN

Book title (not the title that goes with the above ISBN)

Book title

 

Book title

ISBN

ISBN

 

Book Title

ISBN

Extra information

 

It is crucial that the correct ISBN remains with the correct Book Title. I'm going to guess that it is probably too complicated that sometimes there is a third line with extra info, and sometimes there are only two lines.

 

I don't have the first clue on what terms to use, and my grasp of this language is extremely limited since I learnt about its very existence yesterday, and I am no programmer. However, seeing your bits of code and looking up what some of those symbols mean, I edited it down to:

 

Find What

(.+)\r(.+)\r

Change To

$2\r$1~M

 

Which seems to allow me to switch two lines around with a couple of clicks of a button, instead of the more laborious manual procedure of having to carefully highlight the words and cut and paste them down a line. So that is fantastic! I can use this for several two-line swaps, and if I come across a three line thing I'll just have to do that manually. Or if there are several three-line swaps in a row I can edit the GREP code to do that for a bit.

I am completely failing to google and find out what the \r means, I'm assuming it means return?

Is there something to differentiate between a paragraph return and a soft return? It would be useful to ignore soft returns and have it move things that end with a paragraph break.

 

I'm finding this quite exciting and fascinating!

 

-Rachael

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 ,
Oct 16, 2021 Oct 16, 2021

Copy link to clipboard

Copied

Hi Rachael,

You guessed it right that missing 3rd line would cause an issue. I am not able to come up with a grep that can handle 2 and 3 lines. This and the price thing might need a script to handle. Regarding your other query \r denotes "End of Paragraph" and \n denote "Forced line break"

-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
Community Beginner ,
Oct 17, 2021 Oct 17, 2021

Copy link to clipboard

Copied

Brilliant Manan!

Thank you very much for your help with this.

 

Right now I know even less about scripts than I do about GREP, I think that I will stick with this moderate success which will save me a lot of time.

 

Cheers,

Rachael

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 ,
Oct 17, 2021 Oct 17, 2021

Copy link to clipboard

Copied

Like Manan Joshi I've been unable to come up with a GREP solution that I think will work for you without a very rigid data structure. I'm not a scripter, unfortunately, but I do think this is probably scriptable, particularly if you have assigned paragraph styles to the different types of paragraphs (different style for ISBN, Title, and Other info) which would allow a script to identify when paragraphs are missing, as well as to kick the price out and add it to the following line.

 

You don't happen to have all this stuff in a spreadsheet bu chance? It looks like a list that might have been created using Data Merge or simply placing a spreadsheet. If you do, it might be a lot easier to rearrange columns in the spread sheet or the order of data placeholders in the merge template and rebuild the document.

 

Haven't test this thoroughly, but the following GREP find/change seems to work to move your price to the next line (which will allow you to just deal with rearranging paragraphs as a separate problem):

Find (^\d+.+)(\$\d+)(\.\d{2})?(\r)

Change $1$4$2$3 |   (note there are spaces on either side of the "|")

in the Find field the ^ indicates the start of the paragraph, so it will only find paragraphs that start with numbers. | in th e find filed would mean "or" but in the change field it is used literally. In a similar vein, in the find field the . stands for any character so I've "escaped" it to make it literal there. I've also broken the price into dollars and cents parts in case there are cases where the is no cents component to the price.

 

For a good primer on GREP I highly recommend Peter Kahrel's book GREP in InDesign which you can find in a variety of formats on Amazon.

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
Community Beginner ,
Oct 17, 2021 Oct 17, 2021

Copy link to clipboard

Copied

Hi Peter,

 

Thank you! I will give that a go, it would be very useful to not have to manually move all of the prices that are stuck on the ISBN line.

 

There is a spreadsheet of everything, but it will be in an entirely different order from what happens to be in the catalogue because the books are arranged in series and roughly by age group. I am very leery of trying anything too exotic, so I think I'll stick with manipulating the copy that is in the indd files.

 

These lines of text have precious paragraph styles applied to them, and an annoying number of character styles applied inconsistently. The previous person who worked on this catalogue for several years in a row seems to have been allergic to paragraph styles, guidelines, margins, and just consistency in general. Her files are a mess - but it is still faster to start with them and edit them than to pull in all of the content from scratch. This way at least I have all of the book covers inserted for me already, and whilst the copy needs re-arranging it does all exist under the correct book images.

 

A special thank you for taking the extra time to explain what each of the symbols/characters mean and do! I'm finding it a little random to search for InDesign GREP characters to learn what they mean/do. I did find this: http://www.ericagamet.com/wp-content/uploads/2016/04/Erica-Gamets-GREP-Cheat-Sheet.pdf but it seems far from comprehensive. I'll check out your recommendation, it's great to have a suggestion on where to even start! I have come across Peter Kahrel's name a fair bit during the past few days of google searches.

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 ,
Oct 17, 2021 Oct 17, 2021

Copy link to clipboard

Copied

On my way back out for the day so I don't have time to do more work, but it occurred to me that the GREP I posted earlier could be tweaked a bit more to remove trailing white space after the ISBN when you move the price.

 

Also, not sure it's possible, but perhaps a GREP to find cases where the info paragraph is missing and add a blank before running Manan'a code would work.

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
Community Beginner ,
Oct 17, 2021 Oct 17, 2021

Copy link to clipboard

Copied

Oh wow, that GREP to move the price down a line works like MAGIC!

I edited the Change To to become:

$1$4$2$3\s|\s

Because why not have it add in the visual separator whilst it's at it! 😃 So cool. Very satisfying and exciting!

 

------

 

Now, whilst I am grasping this well enough to add spaces where I want, and your previous post mentioned how to add in the | as itself into the text, I do not have the faintest idea how to get it to remove an unknown number of possible spaces after an ISBN. Being able to do that would be very useful because the GREP style (I managed to copy by finding another post with a similar issue, and then edit to suit my needs) applies a character style to the last 6 digits of the ISBN to make them bold. Like this:

9781474 92212 8

.{8}$

When there are spaces at the end of it, it messes it up and not enough of the numbers are put in bold. HOWEVER... perhaps there is a different solution to this problem. Maybe I do not need to worry about how many spaces are at the end of the ISBN? Maybe I need a different term in the GREP code which will apply the character style to the last 6 digits instead of the last 8 characters? Then any superfluous spaces at the end of the ISBN would no longer matter (they'll still annoy me, but they wouldn't matter).

Been through a few different attempts to make that work, but I just don't understand how things work together, and none of my random rearranging of terms has made it work yet. My analogy of my lack of knowledge here is that this is like I am starting to be able to recognise individual letters, but I can't yet make sense of any of the words, let alone know how to put together a sentance.

 

This was my attempt to get my bold character style GREP to apply to the last 6 digits of the ISBN:

(?!$)\d6

Result: 9781474 96789 1 

I thought what I had put in was to look 6 digits ahead of the end of the paragraph. But the best I've gotten is this where it applies the character style to the 9 and 6. I've tried a few different look behind, look ahead, positive, negative things. The snag is that I do not understand what the difference is between a positive look ahead and a negative look ahead. I suspect that what it is currently doing is finding a 6 and applying the style to the literal 6 and the digit before it for some reason. So I googled for how to specify a certain number of digits and I tried this:

(?!$)\b\d{6}

Result: 9781474 96789 1 

The first 6 digits are now in bold, which is a step in the right direction, but I've now lost track of how many different things I've tried with the lookahead/lookbehind part. I am trying to muddle through this, but I'm not sure what keywords I need to even google for at this point. I found something for locating the Nth character from the end, but that is not what I want.

 

I've now probably spent much too long trying to figure out this one little thing in a language that I don't understand, when you'll take one look at it and just tell me what I need to copy and paste in. But I'm finding this really interesting and got rather distracted by the puzzle of trying to figure out how to make it do what I wanted it to do. Alas, I had better hit post and get back to the grind of editing this catalogue for a few more hours before my D&D this afternoon.

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 ,
Oct 17, 2021 Oct 17, 2021

Copy link to clipboard

Copied

LATEST

The GREP query to remove trailing white space from any paragraph is Find: \s+$ and leave the change field blank. That's something I usually run early on in any editing project.

 

You could use Find: (?<=\d{7}\s)\d{5}\s\d to find the last 6 didgits of an ISBN regardless of waht comes before or after it. This uses a Positive Lookbehind (click the little @ symbol next to the find filed and you'll see Match in the dropdown where you can choose positive or negative look ahead or behind) to match five digits, a space, and one digit, but only when they are preceded by sven digits and a space.

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