Skip to main content
C.Lor
Participant
January 20, 2023
Answered

GREP Style, for limited amount of words and symbols before a colon

  • January 20, 2023
  • 2 replies
  • 1851 views

Hello,

Anytime I have a colon at the start of a paragraph, I would like the words and symbols up to and including the colon bold and underlined. I have been using this which I found in another forum: 

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

 

An Example: Looks like this every time up to 3 words. Exactly what I need.

But This (BT): Does not change to my bold/underline style, even if I increase the range from {1,3} to {1,10}

+1 Not Working: It also fails to work with other symbols. 

 

Something like this might work: ^.*?(?=:)

However, I have a few instances of a colon at the end of a long sentence, and don't want the bold/underline style applied then. I'm relatively new to GREP and while I'm starting to grasp it, some things still escape me entirely. Any suggestions would be greatly appreciated.

 

This topic has been closed for replies.
Correct answer FRIdNGE

^([^:\h]+\h?){1,3}(?=:)

 

(^/)  The Jedi

2 replies

FRIdNGE
FRIdNGECorrect answer
January 20, 2023

^([^:\h]+\h?){1,3}(?=:)

 

(^/)  The Jedi

C.Lor
C.LorAuthor
Participant
January 20, 2023

That worked perfectly! I'm not familiar with \h, what does that do?

 

m1b
Community Expert
Community Expert
January 21, 2023

\h means any space character, including tab for example.

jmlevy
Community Expert
Community Expert
January 20, 2023

Why don't you use a simple nested style?

C.Lor
C.LorAuthor
Participant
January 20, 2023

Thanks for the suggestion but that applies it to everything except the words in the sentence that immediately follow the colon. I don't believe a nested style will work the same way a GREP style can, since a GREP can be much more targeted to a specific instance.