Copy link to clipboard
Copied
Hi Gang,
How would you make a GREP to find the last word in the paragraph in order to italicize it?
Best,
Mike in Washington DC
[-\w]+[[:punct:]]+?$
i.e. string of word characters or hyphen, maybe followed by punctuation, at the end of a paragraph ($)
Or [-\w]+(?=[[:punct:]]+?$) if you want to capture just the word, not the end punctuation.
Peter
Copy link to clipboard
Copied
[-\w]+[[:punct:]]+?$
i.e. string of word characters or hyphen, maybe followed by punctuation, at the end of a paragraph ($)
Or [-\w]+(?=[[:punct:]]+?$) if you want to capture just the word, not the end punctuation.
Peter
Copy link to clipboard
Copied
Thanks Peter:
It works! Mostly. It does not like the final paragraph, though, which closes with a double quote.
Tell me, Peter, what does the initial - sign mean?
Copy link to clipboard
Copied
Your second version covers everything nicely! This is based on a question from a student in my classroom today. Thanks for the help!
Copy link to clipboard
Copied
[-\w] stands for 'hyphen or word character'.
Copy link to clipboard
Copied
Peter, many thanks again. The addition of the hyphen sounds like the decision of an experienced one!
Copy link to clipboard
Copied
Hi Peter,
Another approaches:
\H+[-\w]+\W*?$ (Green)
[-\w]+(?=\W*?$) (Orange)
These codes "seem" to catch the "last word" taking in account its context (before/after, except space, taken or not taken)!
(^/)