1 Reply Latest reply on Apr 18, 2012 2:26 AM by Peter Spier

    I am trying to write a grep search for the first instance of a word in a paragraph.

    BodoniLynn

      How can I identify only the first instance of 'FREE' in a paragraph and apply a style to it, without also styling the 2nd or more instance of the word?

       

      Thanks

        • 1. Re: I am trying to write a grep search for the first instance of a word in a paragraph.
          Peter Spier Most Valuable Participant (Moderator)

          (?i)^(.+?)FREE should find the first instance in a paragraph. The (?i) makes the search case insensitive in case it wasn't typed as all caps, the ? inside the second grouping makes the shortest match for cases when there is more than one instance in a paragraph, and I've not added any quotes since I presumed those aren't actually in the text.

           

          I would deal with the formatting by typing FREE exactly as you want it someplace on the pastebord, then copy to the clipboard. Change to $1~c which replaces the found string with the text found in the first subexpression (.+?), which is the stuff before the first FREE, and the the formatted contents of the clipboard for the FREE.