Copy link to clipboard
Copied
I have a par style with a grep style to format the last word of the paragraph of that style (hebrew/arabic). I set teh correct char style and then used this grep code:
[[:alnum:]]+[[:punct:]]?$
(Don't think i know grep. I got from ChatGPT)
It absoltlrly refuses to obey. I admonished Chatgpt and is gave some others but they all refuse to commit, Why is ID refusing to follow orders?
Thank you
Susan Flamingo
Those posix alnum and punct are typically only latin characters - from my understanding
You probably want “the last run of letters/numbers” but not the final punctuation. You could try:
\S+?(?=[[:punct:]]?\r?$)
That way it matches the last word, but only if it’s followed by an optional punctuation mark and then the end of the paragraph.
Another option:
\S+(?=\s*[[:punct:]]?\s*$)
which is more forgiving if there’s a space before the punctuation.
If you can show us some sample text of before a
...Well, this is pretty curious. When I open your sample file here on my US version, everything is fine (I edited the style to make it red for easier identification while testing).
This makes me think there might be a problem in the ME build, in which case no amount of tweaking that GREP expression will make a difference, BUT I'm going to suggest a possible workaround: Add a SECOND GREP Style to your paragraph style for \]$ and use it to apply the [None] character style.
I don't know if it will mak
...Copy link to clipboard
Copied
Try this (assuming that there is a final dot at the end of the paragraph):
\w+\.$
Copy link to clipboard
Copied
It did not work for me. I have tried so many suggextions and nothing has worked. I am working in Hebrew/Arabic.
Finally this did it: \S+?(?=\r|\z) and it worked! (but one thing: this "captures" the last word of the paragraph TOGETHER with the last charachter which is usually a period but sometimes something else. Do you know how to tell it not not to incluse the last char?)
Chat GPT told me that grep styles are very finicky and can get messed up for a lot of reasons. How true is that?
Copy link to clipboard
Copied
So...
@jmlevy 's expression says find all word characters (a-z, A-Z, 0-9, and underscore) followed by a period and the end of paragraph. From my reading, it appears that it does not match Hebrew and/or arabic characters. The use of non-Latin characters is an important bit of information.
\S+?(?=\r|\z) matches any non-whitespace characters (shortest match, triggered by the ? after the + sign, but in fact that probably is not doing anything;\S is the negaive of \s which is any whitespace). followed immediately by a paragraph return or the end of story (\r is the paragraph return, | is "or" and \z is end of story). This expression will also fail if there is any trailing white space at the end of your paragraph (an extra space after the last period, for example).
Since $ indicates the end of paragraph, even without a return at the end of a story, it is a much more compact way of saying \r|\z . \S+\s*$ finds all non-whitespace characters along with any trailing whitespaces if they exist, immediately before the end of a paragraph ( the * after the \s means match zero or more occurences, so it picks up paragraph with or without the trailing spaces).
It's not so much that GREP styles are finicky as that GREP expressions themselves can be tricky to design to match all of the text cases you want to find, and only those cases. There are times when it simply isn't possible to do with a single expression, and it is necessary to to use Find/Change with a series of expressions to accomplish the task.
Copy link to clipboard
Copied
@SuzzyFlamingo , @jmlevy 's answere should work, but I wanted to recommend to you Peter Kahrel's GREP tutorial:
https://www.amazon.com/GREP-InDesign-InDesignSecrets-Peter-Kahrel/dp/0982508387
It's comprehensive and actually pretty easy to follow, and you won't be sorry for aquiring your own GREP skills
Copy link to clipboard
Copied
Hi @Peter Spier Absolutely, your book is a must have!
Copy link to clipboard
Copied
It's not my book, it's by @Peter Kahrel
He's an absolute wizard.
Copy link to clipboard
Copied
Oups! That's what happens when you answer too fast… and yet, I have this book!
Copy link to clipboard
Copied
Those posix alnum and punct are typically only latin characters - from my understanding
You probably want “the last run of letters/numbers” but not the final punctuation. You could try:
\S+?(?=[[:punct:]]?\r?$)
That way it matches the last word, but only if it’s followed by an optional punctuation mark and then the end of the paragraph.
Another option:
\S+(?=\s*[[:punct:]]?\s*$)
which is more forgiving if there’s a space before the punctuation.
If you can show us some sample text of before and after we'd have a better understanding of what you're after.
Copy link to clipboard
Copied
Well, no "before and after" because both don't work (they continue capturing the last character, which is - "[" - and not just the last word without that....bummmer.
What now?
Copy link to clipboard
Copied
Sorry, missed the part where you don't want to capture the last character. Is it always [?
if so, try \S+(?=\[$) but this only will work if [ is the very last character, no space or punctuation following.
Copy link to clipboard
Copied
Another question...
Is the correct language already assigned to those words, or is the GREP style being used to assign it? Since you seem to have two languages involved, you can't be using the a GREP style to do twolanguage assignments using the same pattern, so I suspect that means the language is already applied.
If that's true, as @TᴀW mentions in at least one other thread, you can use the language assignment, either as the determining factor for a match, or as a qualifier to prevent changes to ther text that would match, but has the wrong language applied.
Copy link to clipboard
Copied
Your suggestion of: \S+(?=\[$)
doesn't work. As i think i mentioned, i am working in Hebrew/Arabic, so maybe this is the problem. I think I will have to give up on grep and then simply change the last word at the end of the job via find and replace. So now my question is how do I search for the last word in the paragraph and change its style, and then go change the style of the "]" alone back to the regular"
So I would search for any Word that ends with a ] (no other words like this formatted with that par style) .
How to?
Copy link to clipboard
Copied
Your suggestion of: \S+(?=\[$)
doesn't work. ...and then go change the style of the "]"
By @SuzzyFlamingo
UMMM.. in your post abpve you said the last character was "[", but now you say "]" which, if that's really what it is, explains why the GREP doesn't work and chaning to \S+(?=\]$) should take care of it unless there's a conflict with the bracket characters being different for Hebrew or Arabic.
It would be useful to select your bracket and open the Glyphs panel to see what character it is. Pasting it in in place of the typed bracket might be necessary if it doesn't come up as the ascii character.
Can you post just a snippet of your text? We're really shooting blind here.
Copy link to clipboard
Copied
UMMM.. in your post abpve you said the last character was "[", but now you say "]" which, if that's really what it is, explains why the GREP doesn't work and chaning to \S+(?=\]$) should take care of it unless there's a conflict with the bracket characters being different for Hebrew or Arabic.
We're going to have to wait until SuzzyFlamingo posts tomorrow, of course, but I think you probably nailed it here, Peter. Because bracket characters, like periods or parentheses, can be bidirectional in InDesign. We don't know if the close bracket character at the end of the line is a [ or a ] as its directionality depends on the language selected, the Character Direction setting, how it was keyed, what the paragraph direction is, and so on. Too many variables! When I build similar GREP queries, to process my translators' work, I'm more likely to use something like
\S+(?=\]$|\[$)
which will catch either [ or ]. That's because I don't know whether my translator rekeyed the whole line, including brackets, or if they just typed over the English with their Arabic/Hebrew/Persian/etc., or if they rekeyed the whole line but switched keyboards back to English just to key the brackets, or any one of a number of possibilities.
Copy link to clipboard
Copied
Glad to see you join in Joel. I fell with your help we'll get to the bottom of the problem.
Curiouos, though, that neither bracket version worked.
Copy link to clipboard
Copied
You're not supplying sample text or files to test on - it's hard to troubleshoot.
Copy link to clipboard
Copied
I tried with both versions of the bracket to no avail
you can see the final bracket is bold and i don't want that just the last word. Being that this text is generated by a script there will never be ANY other chars. Just the last word and the bracket
the text is: (cutted and pasted from ID):
[ההמשך נמצא בעמ' ד"ה הזה]
Copy link to clipboard
Copied
When I paste your text into a text frame here the GREP works fine to find the last word (but it omits the other words in Hebrew). That said, I have a US English version of InDesign, so I cannot control the story direction or aaply any other middle east controls. To figure this out we need an actual .indd file from you, just a single page with a single text frame with one or two paragraphs, formatted exactly as you are doing in your book.
You can attach it to a post made from the web page, but not to an email response.
Copy link to clipboard
Copied
Your continued help and concern is truely admirable and appreciated!
It is late here now (Jerusalem time) but tomorrow I will send a file
Thank you again
Susan
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Well, this is pretty curious. When I open your sample file here on my US version, everything is fine (I edited the style to make it red for easier identification while testing).
This makes me think there might be a problem in the ME build, in which case no amount of tweaking that GREP expression will make a difference, BUT I'm going to suggest a possible workaround: Add a SECOND GREP Style to your paragraph style for \]$ and use it to apply the [None] character style.
I don't know if it will make any difference, but at least here all of your text shows as US English. Assigning the correct language as part of your Paragraph Style will, if nothing else, enable spell checking, and might have other beneficial effects.
Copy link to clipboard
Copied
The workaround works perfectly, so for now we will stick with that and detour all the language issues.
Thank you so much for this!
Susan
Copy link to clipboard
Copied
I'm glad we were able to get it to work for you.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now