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

GREP expression for last line followed by column break

Guest
Dec 27, 2013 Dec 27, 2013

Copy link to clipboard

Copied

For all those reading this, thank you for taking the time to help. I'm a noob at GREP expressions and JavaScript so I appreciate all your time and help with this.

I've written a JavaScript to help my company format some of our work quicker. We have pre-made templates with Character Styles all set up (Body, Header, BodyItalic) etc.

My script works nearly perfectly for identifying patterns and applying the correct Character style.

However my expressions don't work perfectly and any last line of text in the text box (linked), that has a column break, does not get formatted.

This last line is always different depending on the document. So I can't put in constants. They are always variables.

My current GREP expression is .+~M which in theory should find any character that repeats one or more times and is followed by a column break. The problem is, it only finds the last two characters on the line that are followed by a column break.

e.g.

Tribute would be TribuTE

Eulogy would be EuloGY

etc etc

As you can see, they are not always the same words, and could even be a short sentence so I can't just tell it to look for certain words.

I'm trying to work out why the GREP expression doesn't work. Maybe I'm using the wrong GREP symbols? I don't know, so any assistance would be much appreciated.

Thank you in advance.

Scorpio

TOPICS
Scripting

Views

1.8K

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

Enthusiast , Dec 28, 2013 Dec 28, 2013

This column-break thing seems bugy. I have no idea why only the last two characters are found. If I try to find a whole word with \w+ that does not work. I get also weird results if I try \b\w+~M. The good news is, that InDesign does not crash here.

However: There is no GREP for search a specific line, so I would search for a columnbreak and then for the line that belongs to the current found:

app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "~M"; 
var

...

Votes

Translate

Translate
Community Expert ,
Dec 27, 2013 Dec 27, 2013

Copy link to clipboard

Copied

@Scorpio – just tested your GREP in the UI of InDesign CS5.5 v7.5.3 with Mac OSX 10.6.8.
It worked as you tested. Found the last two characters before the column brake. I mean the first instance of that GREP in the document.

And then in searching for the next instance, it crashed InDesign…

That's strange…
I'll retry and report later.

Uwe

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
Guest
Dec 27, 2013 Dec 27, 2013

Copy link to clipboard

Copied

Thanks. I find it quite puzzling, because if you just use the expression .+ it will apply the style to all text. Just by adding ~M to the end restricts it to the last two digits before the column break.

In my tests, yes if you do it straight into InDesign, within the Paragraph Styles and GREP section, it can cause long freezes and crashes, but if you put it into a JavaScript, it works a lot better.

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
Enthusiast ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

This column-break thing seems bugy. I have no idea why only the last two characters are found. If I try to find a whole word with \w+ that does not work. I get also weird results if I try \b\w+~M. The good news is, that InDesign does not crash here.

However: There is no GREP for search a specific line, so I would search for a columnbreak and then for the line that belongs to the current found:

app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "~M"; 
var found = app.activeDocument.findGrep(); 

if (found.length > 0) {
for ( var i = 0; i < found.length; i++ ) {
  var curFound = found;
  var curLine = curFound.lines[0]; 
  curLine.fillColor = app.activeDocument.swatches[4];
}
}

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 ,
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

@Kai – your snippet seems to be a very good idea.

It's working fine in my InDesign CS5.5.


I tested a few GREP expressions in the UI of InDesign around ~M.

One of the strange things is:

If you just looking for ~M in a positive lookbehind like that:

(?<=~M)

you'll get also insertion points right behind paragraph returns or other frame break signs.

And if you are looking for \r in a positive lookbehind:

(?<=\r)

you'll get also insertion points behind all frame breaks.

Note:

The unicode for column breaks, frame breaks and other breaks regaring frames and \r is the same:

\x{d}

If you copy/paste a frame break sign to the GREP input field of the GREP search/replace panel you'll get: \r

Uwe

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
Guest
Dec 28, 2013 Dec 28, 2013

Copy link to clipboard

Copied

LATEST

This worked perfectly, thank you so much!!

I obviously had to change it so it didn't change the text blue and apply my character style instead but it works just how I want it to.

Thank you, and everyone else for all your help.

Scorpio

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