Skip to main content
maxwithdax
Community Expert
Community Expert
January 29, 2019
Answered

GREP - Next two words

  • January 29, 2019
  • 2 replies
  • 596 views

What I am looking to do is use grep to find and apply a character style to proper names.

Example:

Mr. Thomas Jones went to the office with Mrs. Margaret Hatcher.

Mr. Thomas Jones went to the office with Mrs. Margaret Hatcher.

I know that what I want to say is....

Find (Mr./Mrs.) including the next two words

Just dont know how to say the last part in grep.

This is as close as I could figure.

(Mr.|Mrs.)+(w+\s\w+)

Thanks!

Dax

    This topic has been closed for replies.
    Correct answer maxwithdax

    For those wondering I was able to figure it out.

    (Mr\.|Mrs\.)\s\w+\s\w+

    Thanks in part to What the GREP script that helped me figure out what I was doing wrong! Thanks!!!!

    http://www.jongware.com/binaries/whatthegrep-0.1.zip

    2 replies

    maxwithdax
    Community Expert
    Community Expert
    January 29, 2019

    Great to know! Good call winterm​. Planning for variations in advance is always a good thing!

    -Dax

    pixxxelschubser
    Community Expert
    Community Expert
    January 29, 2019

    my own preferred kind

    (M(r|rs)\.)(\h\w+){2}

    also good without an 'OR'

    Mrs?\.(?:\h\w+){2}

    maxwithdax
    Community Expert
    maxwithdaxCommunity ExpertAuthorCorrect answer
    Community Expert
    January 29, 2019

    For those wondering I was able to figure it out.

    (Mr\.|Mrs\.)\s\w+\s\w+

    Thanks in part to What the GREP script that helped me figure out what I was doing wrong! Thanks!!!!

    http://www.jongware.com/binaries/whatthegrep-0.1.zip

    winterm
    Legend
    January 29, 2019

    A bit late to the party

    Great idea to help yourself with Jongware’s script, and I’m sure your improved version will work for you just fine.

    Just a word of caution:

    You probably noticed \s stands for any white space, and this sometimes may lead to unexpected results:

    Often it’s a bit safer to restrict found spaces to horizontal only - \h, or use Unicode representation of an exactly regular space \x{20}

    Or even simply hit spacebar key…