Skip to main content
Mike Witherell
Community Expert
Community Expert
February 2, 2017
Answered

GREP solution last word?

  • February 2, 2017
  • 1 reply
  • 2822 views

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

    Correct answer Peter Kahrel

    [-\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

    1 reply

    Peter Kahrel
    Community Expert
    Peter KahrelCommunity ExpertCorrect answer
    Community Expert
    February 2, 2017

    [-\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

    Mike Witherell
    Community Expert
    Community Expert
    February 2, 2017

    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?

    Mike Witherell
    Mike Witherell
    Community Expert
    Community Expert
    February 2, 2017

    Your second version covers everything nicely! This is based on a question from a student in my classroom today. Thanks for the help!

    Mike Witherell