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 insert a full stop at the end of paragraphs

Return to Member Forum

  • Author
    Posts
    • #82138

      I´m trying to find all instances where a paragraph lacks a full stop (a dot), and insert a full stop at the found occurances.

      I don´t get it working though, I´ve tried with this GREP:

      Search for: ([^.])\r
      Replace with: $1.\r

      But this finds both these paragraphs:

      Paragraph example with full stop.
      Paragraph example without full stop

      In the paragraph example with the full stop, it finds/selects the \r (carriage return)
      In the paragraph example without the full stop it finds/selects the character before \r and \r.

      So, I want to be able to only find instances where any character, except a full stop, is followed by \r. And I don´t want to find instances where the character next to \r is a full stop.

      How do I solve this?

    • #82139

      I don’t know GREP, I would do this in two steps with Find/Replace.

      Find: ^p
      Replace with: .^p (this will leave some paragraphs with two full-stops) So:

      Find: ..
      Replace with: .

    • #82140

      Thanks for a swift answer!

      However this finds every paragraph mark ^p, the ones that already have a full stop as well as the ones without. I don´t want to find the ones that already have a full stop, only the paragraphs lacking them.

    • #82143
      Peter Kahrel
      Participant

      Samuel,

      You were very close. Instead of ([^.])\r, use ([^\.])$.

      The dot in your [^.] matches any character. To match just a dot in the text, use \.
      Also, if you use \r you won’t match the last paragraph in a story if the story doesn’t end in an empty paragraph. $ matches the end of the paragraph even when it’s not followed by a return character.

      Colleen: using ^p (or \r for that matter) in replacements can lead to strange results at points where the paragraphs before and after the ^p have different paragraph styles.

    • #82151
      Peter Kahrel
      Participant

      > The dot in your [^.] matches any character. To match just a dot in the text, use \.

      Which is complete nonsense, because the dot is in a character class so that there’s no need for the backslash. Now that I tried your original ([^.])\r and $1.\r I find that they work fine over here. Though I still think that $ is better than \r, so use ([^.])$ and $1.

    • #82152
      Peter Kahrel
      Participant

      So the question is, why doesn’t it work for you?

      (If only one could edit one’s messages. . .)

      • #82153
        David Blatner
        Keymaster

        I thought that you could edit messages, but we’ve recently heard from people saying that it doesn’t work. We’ll investigate.

    • #82261
      Mats Leidoe
      Member

      Tried this a few times back and forth, but find it hard to make the Regex find only sentences without full stops. One commonly recommended method is using (?!) to match negative lookbehind, since regex doesn’t use “not” (there is only “or”, where you use the pipe |). But using negative lookbehind on full stops only yields strange results in InDesign, or maybe I just don’t master it. So, what’s left? Well, I would use brackets.
      search for:
      ^\u[\u\d\ -,]+$
      replace with:
      $0.
      works for me. It will match
      ^:from the beginning of the line
      \u:one upper case character (as this was meant to match sentences, not just single words, like short captions, I prefer having that \u up front)
      [\u\d\ -,]:any upper case, lower case, digit, space, comma or dash
      +: repeatedly until
      $: the end of the line (but not including the paragraph break, which is a good point, and it means we can ditch the parenthesises, thanks Peter Kahrel)
      If you need to match other characters, like exclamation mark, add them (with a backslash before if necessary) inside the bracket.

    • #82263
      Mats Leidoe
      Member

      P.S. You can’t use the inside the brackets, even though it is very tempting, since means “any white space”, which apparently includes not only all kinds of spaces and tabs, but paragraph breaks and line breaks as well.

Viewing 7 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads