Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

GREP Code to Find Text Enclosed by $ Signs

Engaged ,
Nov 04, 2021 Nov 04, 2021

Hi folks

 

A client has passed me a manuscript where all text to be italicised is enclosed in $ signs e.g. $italicise this$. This seems like a perfect job for GREP, but I cannot get it working consistently.

 

Text between $ signs may include any other text i.e. letters, digits, whitespace\newline, punctuation

 

Goal is to find each instance, italicise the text, and remove the $ signs.

 

My current GREP query is shown below (see screenshot for full search), but it misses many instances:

 

Find: (\$)(.+)(\$)
Replace: $2 (Change format to “Italic” character style)

 

Any help appreciated!

 

Thanks
Richard

 

Capture.JPG

 

 

TOPICS
How to
314
Translate
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
Community Expert ,
Nov 04, 2021 Nov 04, 2021

Hi Richard,

isolate some of the not found instances and make a document available we could test.

One page with some text frames should be enough…

 

Thanks,
Uwe Laubender

( ACP )

Translate
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
Engaged ,
Nov 04, 2021 Nov 04, 2021
LATEST

Thanks for your reply - unfortunately the text is confidential so I won't be able to offer a sample, but thanks in any case!

Translate
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
Community Expert ,
Nov 04, 2021 Nov 04, 2021

I'm surprised you say it's missing instances rather than including too much.

I think I would use Find: (\$([^$\r]+)\$) and change to $2 with your italic formatting.

The [^$\r] is a negative class that finds any character not a dollar sign or paragraph return. This prevents a match that crossses a paragraph boundary. It might not be what you want, however, as you mentioned a newline, but I'm thinking that is really a forced line break rather than a paragraph break. If you need to italicize multiple entire paragraphs some of which have no $ at the stasrt or end, remove the \r. Note that this could fail miserably if there are any cases where there is text with only one dollar sign, like a price.

I'd test this out on a copy of the file....

Translate
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
Engaged ,
Nov 04, 2021 Nov 04, 2021

Thanks for your replies - I'll give that a go.

Translate
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