GREP First Instance Only

Explorer ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

I have a large directory I'm trying to format. Each entry has a list of items followed by a descriptive paragraph. Each item in the list has a label followed by a colon. I want to style the label along with the colon, making them bold and all-caps. I had success with the following expression:

.+\:

Which ends up like this:

PHONE NUMBER: 123-456-7890

WEBSITE: www.adobe.com

The problem is, that occasionally one of the descriptive paragraphs will also have a colon, resulting in this:

OVERVIEW: THIS TEXT SHOULD NOT BE STYLED: and should return to normal after only the first colon.

I've been trying various expressions to get it to work and either I get all the text styled, none of the text styled or the above problem. Any help is appreciated! Thank you!

TOPICS
Scripting, Type

Views

322

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

LEGEND , Aug 12, 2020 Aug 12, 2020
GREP is greedy by default; it tries to match as much as possible. Make your expression non-greedy by adding a question mark: ^.+?: or use a nested style "Up to" and then type a colon.

Likes

Translate

Translate
LEGEND ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

GREP is greedy by default; it tries to match as much as possible. Make your expression non-greedy by adding a question mark:

 

^.+?:

 

or use a nested style "Up to" and then type a colon.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

Copied

Thank you! Worked like a charm; I was putting the ? AFTER the colon, and also escaping the colon..

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

Similar case. But I want to get the found string without the colon.

If I would use following term it would be the same problem, it will become greedy:


Searching for:

(.+)?:

Replacing with (formatted): 

$1\r

 

That's the result:

mycc_0-1618790771508.png

Is there any solution to search for "OVERVIEW:", but replacing it with "OVERVIEW[new paragraph]" = not with the colon?

 

THANKS!

mycc

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

LATEST

Try this:

 

find:(.+?):

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines