Skip to main content
Inspiring
August 19, 2013
Answered

GREP to find up to 3 words in a row followed by colon

  • August 19, 2013
  • 1 reply
  • 2129 views

I usually have to do the repettive task of indenting dialog in a script. See image. I am trying to write a script that involves a GREP find/replace that will find the following:

From the beginning of a paragraph, find one to three words that are followed by a colon.


This is a GREP expresssion i have writtern to so far. It worked fine until i realized that it is greedy in it's search. As you can see in the case of the line with  time in there. It avoids the first colon and greedily grabs the next one from the time stamp.

What is the solve for this? Is there a better regex expression? Any help would be great.

The GREP i have so far.

^((?:\w\S*)(?:\s)?(?:\w\S*)?(?:\s)?(?:\w\S*)?):((\t+)?(\s+)?)?

This topic has been closed for replies.
Correct answer Trevor:

^(((?!:)\w)+\s?){1,3}?:

:-)

Trevor

1 reply

Trevor:
Trevor:Correct answer
Legend
August 19, 2013

^(((?!:)\w)+\s?){1,3}?:

:-)

Trevor

tushardeAuthor
Inspiring
August 19, 2013

Trevor, my HERO!!! That worked perfectly. Thanks for the quick response. Appreciate it. Thanks again.