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 choose first letter of every word in paragraph

Return to Member Forum

  • Author
    Posts
    • #65000
      Chris Lane
      Participant

      I have the following GREP to choose the first letter of each word in a selected paragraph, excluding particular words such as of, the, and, etc. The problem is the GREP does not include the first letter of the first word of the paragraph (since it is a positive look behind for a space, followed by any character)-there is no space at the beginning of the paragraph. I also need the GREP to include the first letter of the paragraph regardless of what the word is; even the words I am excluding in the rest of the paragraph. I am close but can’t figure out how to include that first letter. Any help?

      (?<= )[\u](?!(f|he|nd?|o|y|rom|or|s|t|r|hat)?)

    • #65013

      Try this: \<[\u](?!(f|he|nd?|o|y|rom|or|s|t|r|hat)?)

      I replaced the GREP at the beginning looking for a space followed by a character with the GREP location “Beginning of Word”

      Let me know how it goes!
      Kimmi

    • #65067

      Kimmi, very good, you had the same idea I had — except for two small nitpicks that chrisl overlooked :)

      1. I copied chrisl’s question to use as test text, and it starts with the word “I”. Since it doesn’t appear in the list of ignored words, it should be marked — but this GREP always needs at least *two* characters.

      2. It is ignoring *any* first character, when followed by the 2nd to last characters of the To Ignore list. So “?rom” is to check for “from”, but it will also ignore “prom”; “?hat” will ignore “that” but also “chat”, and so on.

      The following uses the same idea, but with these points corrected (I also prefer for word break, for no special reason at all):

      (?!(for|of|the|and))[\u]

      and if capitalized words need skipping as well, add the Case Insensitive switch at the front:

      (?i)(?!(for|of|the|and))[\u]

      Oh, and to check *any* first letter, all it takes is this:

      [\u]

    • #65069

      Wow, very cool! :)

    • #65085
      Chris Lane
      Participant

      I agree–VERY cool. Thanks Kimmi and Jongware, this is exactly what I am looking for.

    • #70485

      Hi,

      I have a similar situation but I’m not sure if it’s possible or not. Any help would be great.

      I’m laying out a book that has little handwritten notes scattered throughout. I have a font that looks good for the lowercase letters, but the caps look foolish. I’m wondering if there’s a way to use GREP to apply a character style to only the capital letters (to use a better font) in a paragraph and then use the other font for the rest of the lowercase text.

      Any ideas?

    • #70486
      David Blatner
      Keymaster

      Sure! Just make a GREP style that applies a character style (which changes the font, or whatever) and use the code \u (backslash-u). That means “any uppercase character.”

    • #70487

      Ha ha, that was a little more simple than I thought. Thanks!

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