Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

GREP to find proper name BUT exclude a titles

Return to Member Forum

  • Author
    Posts
    • #34289
      Clair Koroma
      Participant

      Hello, I need to write a GREP expression that allows me to look for all proper names BUT excludes specific words in that name search to avoid titles that follow the same pattern as proper names. For example, I want to find John Smith, but don’t want to find Assistant Chief. The GREP expression that I am using to find proper names is:
      (\u\w+) (\u\w+)

      As you can see it will find first and last names in a pattern, but will also find any titles that follow that pattern. Is there a way to include in the expression instructions to exclude specific words in the name search to narrow it a bit. so find John Smith but don’t include any expressions in the pattern that have the word Assistant, Chief…?

    • #34297
      Justin Sligh
      Member

      Clair,

      How are the names and titled used within the paragraph.
      Do they have their own text frames, are they in their own paragraphs, or are they within a narrative?
      Is there a delineator between the name and the title, such as a comma?

    • #34305

      Clair, it’s possible to exclude entire phrases out of an otherwise “catch-all” GREP query, but you have to list each one of them.

      You can try this:

      (?!(Assistant|Chief))(\u\w+ \u\w+)

      This ‘looks ahead’ for either “Assistant” or “Chief”, followed by a word break — the break is to prevent the Chieftains Museum, Rome, Georgia, being ignored. (A somewhat constructed example I admit, but you SHOULD check for entire words, just in case.)

      I THINK you only need to check the first word here; in the case of your “Assistant Chief”, the “Assistant” is the one that gets ignored right away and ID will not contemplate “Chief”, unless it is followed by yet another capitalized word. And then “Chief” and that word in turn are ignored, unless there is a FOURTH capitalized word following (in which case only the two last words are found, as presumably is the intention here).

    • #34318
      Clair Koroma
      Participant

      @Justin, the names are in a paragraph, no commas or delineators, randomly throughout the text.

      @Jongware, THANK YOU, this formula works:-) There a quite a few titles for which I have to look BUT not so many that I cannot include them in the look ahead. Makes my life much easier.

      Now, let’s say I wanted to incorporate this grep into a paragraph style where we find the proper names and whenever, those names are found, neither the first or last name should be hyphenated in the event of a line break, thoughts? If I assign a no break to the entirety of the expression it appears to try to keep the entire name together at all times and the hyphenation feature nested in paragraph styles.

    • #34320
      Clair Koroma
      Participant

      Alas, I think I figured it out. I nested the GREP in a paragraph style and applied a “no language” character style to the string. So far the tests work, the first and last name can break lines, that is rest on separate lines BUT neither the first nor last name will hyphenate and rest on separate lines.

    • #34321
      Justin Sligh
      Member

      Clair,

      I was going to say

      (?!(Assistant|Chief)))(?=(\u\w+ \u\w+))(\u\w+ \u\w+)

      With an associated character style of no-break

      Your method is far simpler. I like it!

    • #34322
      Clair Koroma
      Participant

      Thanks Justin:)
      I initially tried the “no break” option but the problem was that it applied it to the entire name so that John Smith always had to exist on the same line, John and Smith could not span two lines. With the “no language” style, John and Smith can exist on different lines but neither John nor Smith will hyphenate across lines.

    • #34324
      Justin Sligh
      Member

      Clair,

      The grep was slightly different.
      (?!(Assistant|Chief)))(?=(\u\w+ \u\w+))(\u\w+ \u\w+)

      It was Jongware’s initial expression with the addition of a positive lookahead.

      Jongware’s is saying, look for an instance of two capitalized words in a row that do not include “Assistant” or “Chief”.

      Mine would be a second Grep Style that says, look for an instance of two capitalized words only when there are two capitalized words preceding it and they don’t include “Assistant” or “Chief”. It no-breaks just the names.

      Setting to “No Language” in Jongware’s original expression is a fantastic idea. That is why I love these forums. I am always learning a new trick.

    • #34325
      Clair Koroma
      Participant

      Ah Justin, I did not see your expression. I will add it to my GREP library for reference in my future quests for formatting dominance over my long-doc layouts. Thanks for sharing.

Viewing 8 reply threads
  • You must be logged in to reply to this topic.
Forum Ads