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

GREP solution last word?

Community Expert ,
Feb 02, 2017 Feb 02, 2017

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

Mike Witherell

Views

2.0K

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

Community Expert , Feb 02, 2017 Feb 02, 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

Votes

Translate

Translate
Community Expert ,
Feb 02, 2017 Feb 02, 2017

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

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 ,
Feb 02, 2017 Feb 02, 2017

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?

Mike Witherell

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 ,
Feb 02, 2017 Feb 02, 2017

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!

Mike Witherell

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 ,
Feb 02, 2017 Feb 02, 2017

Copy link to clipboard

Copied

[-\w] stands for 'hyphen or word character'.

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 ,
Feb 02, 2017 Feb 02, 2017

Copy link to clipboard

Copied

Peter, many thanks again. The addition of the hyphen sounds like the decision of an experienced one!

Mike Witherell

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
LEGEND ,
Feb 02, 2017 Feb 02, 2017

Copy link to clipboard

Copied

LATEST

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)!

Capture d’écran 2017-02-02 à 22.53.57.png

Capture d’écran 2017-02-02 à 22.52.10.png

(^/)

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